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

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.

Replies are listed 'Best First'.
Re^3: use File::Basename - need to specify OS?
by pelagic (Priest) on Apr 21, 2004 at 11:18 UTC
    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