Once upon a time, Lázaro Morales <lazaro(a)frioclima.com.cu> said:
Hello folks,
This question is a bit off-topic but the Fedora Community is awesome. This
is the question, How can I from this string:
my $url = "http://somesite.org/somefile.zip"; # Example URL
obtain only this sub-string:
my $file = "somefile.zip";
Of course, being perl, there's more than one way to do it. :)
I would do something like:
my ($file) = $url =~ m!^http://[^/]+/(.*)!;
That would strip off the leading protocol/host, leaving the rest. If
there was a subdirectory in the URL (e.g.
http://host/some/file.zip) the
above would result in $file = "some/file.zip".
If you always only want the last part (following any slashes):
my ($file) = $url =~ m!([^/]+)$!;
This would take
http://host/some/file.zip and give $file = "file.zip".
--
Chris Adams <cmadams(a)hiwaay.net>
Systems and Network Administrator - HiWAAY Internet Services
I don't speak for anybody but myself - that's enough trouble.