in reply to Re^2: Strip part of url
in thread Strip part of url

I agree about the URI recommendation but that code works fine on OS X.

Replies are listed 'Best First'.
Re^4: Strip part of url
by afoken (Chancellor) on Feb 13, 2011 at 08:52 UTC

    "Mac OS" ne "OS X". Mac OS has ":" as path delimiter, OS X is derived from Unix and thus has a "/" as path delimiter.

    File::Basename can change its idea of the operating system, so you can see the problem on every operating system:

    use File::Basename; my $url = "http://google.com/folder/1234.html"; print "Native: ",basename($url,'.html') +,"\n"; fileparse_set_fstype('Unix'); print "Unix: ", basename($url,'.html') +,"\n"; fileparse_set_fstype('MacOS'); print "MacOS: ", basename($url,'.html') +,"\n";

    Output on Windows:

    Native: 1234
    Unix: 1234
    MacOS: //google.com/folder/1234
    

    Abusing that feature to force Unix semantics doesn't really help:

    use File::Basename; my $url = "http://google.com/folder/1234.html?session=4247110815"; print "Native: ",basename($url,'.html') +,"\n"; fileparse_set_fstype('Unix'); print "Unix: ", basename($url,'.html') +,"\n"; fileparse_set_fstype('MacOS'); print "MacOS: ", basename($url,'.html') +,"\n";

    Output:

    Native: 1234.html?session=4247110815
    Unix: 1234.html?session=4247110815
    MacOS: //google.com/folder/1234.html?session=4247110815
    

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Well… OS X is just Mac OS 10 but I take your point. I actually thought you might have meant that later but it seemed too strange. I'd wager I'm the only one here who still runs a Mac on system 9 (and another on 8 actually) and I certainly don't have Perl on any of my old boxes and hardware created (chiefly) to run pre-10 is … 15 years? out of production. So this strikes me as a *highly* academic concern. I still agree that URI (and perhaps Path::Class on the uri->path) is the way to go.