Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: File::Basename is dog slow

by runrig (Abbot)
on Dec 19, 2006 at 19:30 UTC ( #590753=note: print w/replies, xml ) Need Help??


in reply to File::Basename is dog slow

I assume you're talking about this code (from parsefile):
if (@suffices) { $tail = ''; foreach $suffix (@suffices) { my $pat = ($igncase ? '(?i)' : '') . "($suffix)\$"; if ($basename =~ s/$pat//s) { $taint .= substr($suffix,0,0); $tail = $1 . $tail; } } }
It recompiles a regex for every suffix on every call to parsefile. Yuck! This module could use another function that saves a regex to do the suffix checking (in a closure or an object). Or something :-)

Replies are listed 'Best First'.
Re^2: File::Basename is dog slow
by tye (Sage) on Dec 19, 2006 at 20:35 UTC

    How about just defaulting to stripping s{[.]([^./\\]*)$}{} (slightly more portably) instead of having to pass in a huge (and likely incomplete) list of possible extensions. That interface never made much sense to me, and hence I don't use it (and I'm not surprised that it is slow). I'd say, if it hurts, stop doing it (use something other than File::BaseName for stripping extensions, such as that regex I show above, which is portable enough for most work, likely). (:

    - tye        

Re^2: File::Basename is dog slow
by petdance (Parson) on Dec 20, 2006 at 06:03 UTC
    Might be. I didn't look into it. I just wanted to avoid it.

    xoxo,
    Andy

      You could keep File::Basename and just stop passing in a list of extensions. Just replace that part of the functionality. Stripping extensions is the part of Basename's parsing that is easy to replace portably, since it is just stripping the list of things you told it to. Keeping the added portability of the rest of the parsing is probably worthwhile and probably isn't dog slow. (:

      - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://590753]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-05-21 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?