Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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

Replies are listed 'Best First'.
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?
[1nickt]: Life is weird. Just reading about the iPhone battery problems and saw: 'It’s like calling water “dihydrogen monoxide”'

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2016-12-06 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (105 votes). Check out past polls.