File::Spec is the long-awaited standard method for doing common tasks with
file names and paths (file specifications or file specs) in a way that is
portable between different operating systems.
The Good
What it can do:
- $cpath = File::Spec->canonpath( $path );
- $dirpath = File::Spec->catdir( $dir1, $dir2, $dir3 );
- $filepath = File::Spec->catfile( $dir1, $dir2, $dir3, $file );
- $curdir= File::Spec->curdir(); # "." on Unix
- $nul= File::Spec->devnull(); # "/dev/null" on Unix
- $root= File::Spec->rootdir(); # "/" on Unix
- $tmpdir= File::Spec->tmpdir(); # "/tmp" or $ENV{TMPDIR}, etc.
- $updir= File::Spec->updir(); # ".." on Unix
- @list= File::Spec->no_upwards( @list ); # Strips "." and ".."
- $ignore= File::Spec->case_tolerant(); # Returns false under Unix
- $abs= File::Spec->file_name_is_absolute($path);
- @path= File::Spec->path(); # Returns $ENV{PATH} as an array.
- ($volume,$dirs,$file)= File::Spec->splitpath( $path [, $no_file ] );
- @dirs= File::Spec->splitdir( $dirs );
- $path= File::Spec->catpath( $vol, $dirs, $file );
- $relpath= File::Spec->abs2rel( $path [, $base ] );
- $abspath= File::Spec->rel2abs( $path [, $base ] );
The Bad
The documentation isn't OS-independent so you have to read the documentation
for each OS-specific component of File::Spec. Start with
perldoc File::Spec then perldoc File::Spec::Unix
(since that part of the module is the most complete).
Not all methods are available on all platforms.
This module isn't available for even slightly old versions of Perl. Until and
unless that changes, you may want to back-port the functionality to older
versions of Perl yourself so that your code will still port to different
OSes.
The Ugly
Getting File::Spec functionality for old versions of Perl in a portable, robust
manner. I hope to add more details on this later.
-
tye
(but my friends call me "Tye")
In reply to File::Spec
by tye
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.