home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book Home Programming PerlSearch this book

32.23. File::Spec

use File::Spec;     # OO style

$path = File::Spec->catfile("subdir", "filename");
    # 'subdir/filename' on Unix, OS2, or Mac OS X
    # 'subdir:filename' on (old) Apple Macs
    # 'subdir\filename' on Microsoft

$path = File::Spec->catfile("", "dir1", "dir2", "filename");
    # '/dir1/dir2/filename' on Unix, OS2, or Mac OS X
    # ':dir1:dir2:filename' on (old) Apple Macs
    # '\dir1\dir2\filename' on Microsoft

use File::Spec::Unix;
$path = File::Spec::Unix->catfile("subdir", "filename");
    # 'subdir/filename' (even when executed on non-Unix systems)

use File::Spec::Mac;
$path = File::Spec::Mac->catfile("subdir", "filename");
    # 'subdir:filename'

use File::Spec::Win32;
$path = File::Spec::Win32->catfile("subdir", "filename";)
    # 'subdir\filename'

# Use functional interface instead.
use File::Spec::Functions;
$path = catfile("subdir", "filename");
The File::Spec family of modules lets you construct paths using directories and filenames without hardcoding platform-specific directory separators. Supported systems include Unix, VMS, Mac, and Win32. These modules all offer a catfile class method that catenates together each path component using the specified platform's path separator. The File::Spec module returns different results depending on your current platform. The others return results specific to that platform. The File::Spec::Functions module provides a functional interface.

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.