Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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

In reply to File::Spec by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (4)
    As of 2014-07-28 23:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (210 votes), past polls