Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

File::Spec

by tye (Sage)
on Sep 13, 2000 at 23:35 UTC ( #32335=modulereview: print w/replies, xml ) Need Help??

Item Description: Portable ways to manipulate file specifications

Review Synopsis: Please try to use this module even when you don't need it

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")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: modulereview [id://32335]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2023-03-22 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?