in reply to Re: file name parsing to get the original file name
in thread file name parsing to get the original file name
If we are trying for 'best UNIX-only solution that requires no modules', I vote for:
my($name) = $path =~ /([^\/]+)\z/;I second Abigail-II's suggestion that a module is used, though, as these sorts of problems are generic in nature, and it is very scary to see hundreds of different solutions to the same problem, each with their own independent set of failings.
At least if a single module is used by everybody, then the code is being excercised in a higher percentage of the possible contexts, and problems will be fixed sooner, rather than being discovered much later.
UPDATE: Optimizing the above expression, we can see the speed improve by a factor of 6:
$path =~ /(?:.*\/)?(.+)/s; my $name = $1;It seems that the Perl regular expression engine does a poor job of dealing with matching a pattern at the end of a string. This is not surprising given that most regular expression engines start searching from the beginning of the string.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: file name parsing to get the original file name (regex performance)
by Aristotle (Chancellor) on Aug 24, 2003 at 05:43 UTC | |
Re: file name parsing to get the original file name
by Abigail-II (Bishop) on Aug 20, 2003 at 08:00 UTC | |
by MarkM (Curate) on Aug 20, 2003 at 20:30 UTC | |
by Abigail-II (Bishop) on Aug 20, 2003 at 21:22 UTC | |
Re^3: file name parsing to get the original file name
by rthawkcom (Novice) on Jun 22, 2011 at 15:54 UTC | |
by MarkM (Curate) on Dec 13, 2012 at 23:55 UTC |