in reply to parsing from the right instead of the left
(my $ext = $url) =~ m!\.([^/]+)$!;
With greedy quantifiers like + and *, the regex engine parses from right to left anyway. So take advantage of that.
Somehow, that construct isn't behaving for me after a long week, so here's another approach:
#!/usr/bin/perl -w use strict; print "Url: "; chomp(my $url = <STDIN>); if ($url =~ m!\.([^/]+)$!) { print "Ext: $1\n"; } else { print "Not found.\n"; }
|
|---|