Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Code Smarter

by salvadors (Pilgrim)
on Dec 31, 2000 at 22:22 UTC ( #49115=note: print w/ replies, xml ) Need Help??


in reply to Code Smarter

So, what's the best way to find of a string ends with a given substring?

On another thread I posted example code for finding all your .mp3 files, and I used rindex, but I dawned on me later that that would also find false negatives like: "foo.mp3.gif"

So what's the best replacement for m/.mp3$/?

Tony


Comment on Re: Code Smarter
Download Code
Re: Re: Code Smarter
by I0 (Priest) on Dec 31, 2000 at 22:41 UTC
    m/\.mp3$/ or substr($_,-4)eq".mp3"
      Anyone know which of these is the faster expression (intuitively speaking, not looking for a benchmark)? Doesn't the RE have to do a lot of work to get to the end of each string passed, whereas substr simply clips? The only thing to remember is to either test .MP3 as well or do lc() on the substr().
        My Benchmark shows the RE slightly faster.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-22 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (113 votes), past polls