kiat has asked for the wisdom of the Perl Monks concerning the following question:
I discovered "use File::Basename" through the responses I got from a node of mine use CGI vs use CGI qw(:standard). I've the following code which works on a Windows machine running apache 2++:
That works. The same piece of code when run on a BSD server "broke" - I needed to add an extra line to get it to work. So the code above was changed to:use CGI; use File::Basename; my $q = new CGI; # $file set to 'C:\Windows\images\hello.gif' my $file = $q->param('file'); # $filename set to hello.gif my $filename = basename($file);
I'm curious why I needed to add the line "fileparse_set_fstype("MSDOS"). I had the impression the function "basename" would automatically detect the type of OS the file comes from and perform the necessary parsing, so you need not worry about the source of the file.use CGI; use File::Basename; my $q = new CGI; # $file set to 'C:\Windows\images\hello.gif' my $file = $q->param('file'); # Added this line fileparse_set_fstype("MSDOS"); # $filename set to hello.gif my $filename = basename($file);
Could someone enlighten me? Thanks :)
Update:
Change the slashes to '\' instead of '/', as pointed out by b10m.
Update2:
On use CGI vs use CGI qw(:standard), The code by jeffa had a line to detect OS:
Which shows that OS detection isn't automatic.fileparse_set_fstype('MSDOS') if $name =~ /\\/;
|
|---|