Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: file name parsing to get the original file name

by MarkM (Curate)
on Aug 20, 2003 at 20:30 UTC ( #285288=note: print w/ replies, xml ) Need Help??


in reply to Re: file name parsing to get the original file name
in thread file name parsing to get the original file name

Interesting. It looks like you've found yet another piece of Perl that isn't implemented in the most optimal manner. :-)

Playing around, I found that on my system, the following tweak allows the 'single regexp match' to beat the 'split into a temporary list, and grab the last entry' approach by ~15%:

$f =~ /(?:.*\/)?(.+)/s; my $fn = $1;

I'm still surprised that Perl can match against '/' several times (split) faster than it can skip to the last '/' with a single rather simple match. It seems the Perl regular expression engine could still use a few optimizations. Until then, I suppose explicit optimization isn't that bad.

Cheers,
mark


Comment on Re: Re: file name parsing to get the original file name
Download Code
Re: file name parsing to get the original file name
by Abigail-II (Bishop) on Aug 20, 2003 at 21:22 UTC
    I'm still surprised that Perl can match against '/' several times (split) faster than it can skip to the last '/' with a single rather simple match.

    I'm not surprised. /(^\/+)\z/ is a rather complicated regex due to the character class being used. The optimizer can't figure out that is the same as "looking for the last slash". m!/! on the other hand is so simple, the optimizer recognizes it as searching for a fixed string.

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://285288]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2014-09-21 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls