Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW


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

Comment on File::Spec
Select or Download Code

Back to Reviews

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-11-29 03:02 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls