Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by MarkM (Curate)
on Aug 20, 2003 at 20:30 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://285288]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-16 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found