in reply to use File::Basename - need to specify OS?

Same as PodMasta ... I usually do it like:
my (undef,undef,$file) = File::Spec->splitpath( $path_and_file );
... works on all OS.

pelagic

Replies are listed 'Best First'.
Re: Re: use File::Basename - need to specify OS?
by eserte (Deacon) on Apr 21, 2004 at 08:37 UTC
    This depends on the originating OS of the given $path_and_file. If I remember correctly, then the path given through a CGI file upload may be in MSDOS format (with backslashes). Processing this filename with basename or splitpath on a Unix system would give wrong results.

    So if you know the path is a MSDOS path, you should use File::Spec::Win32->splitpath instead of File::Spec->splitpath. See here:

    use File::Spec; warn ((File::Spec->splitpath("c:\\foo\\bar\\basename"))[-1]);
    would return c:\foo\bar\basename at ... on a Unix system, while
    use File::Spec::Win32; warn ((File::Spec::Win32->splitpath("c:\\foo\\bar\\basename"))[-1]);
    would return basename at ... on all systems.
      You're completely right when the path originated not from the actual os.
      In that case I'd probably do it a bit primitive like that:
      ($progname = "c:\\foo\\bar\\basename") =~ s!^.*[\\/]!!; warn $progname;

      pelagic