in reply to A better way? Extracting filename from url

What's wrong with using the nice URI module?
use URI; while (<DATA>) { my $file = (URI->new($_)->path_segments)[-1]; print $file, "\n"; } __DATA__ http://www.spied.co.nz/thinmailer.cgi http://www.site.com/dir/file.html?param1=val1&param2=val2

gav^

Replies are listed 'Best First'.
Re: Re: A better way? Extracting filename from url
by theorbtwo (Prior) on Jan 14, 2002 at 21:01 UTC

    This sounds like the best way to me. Don't forget to uri_unescape() (or whatever it's called; I don't quite recall) the filename part to deal with stuff like "file%20name.htm".

    Thanks,
    James Mastros,
    Just Another Perl Scribe