Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

(crazyinsomniac) Re: convert whitespaces to underscores

by crazyinsomniac (Prior)
on May 26, 2002 at 22:29 UTC ( #169439=note: print w/replies, xml ) Need Help??

in reply to convert whitespaces to underscores

I'd replace $file =~ s/\s+/_/g; with $file =~ y/_//sd; and here is why (this is supposed to be a well known fact)
use Benchmark qw( cmpthese ); cmpthese( 100_000, { 's' => sub { $a='a _ b __ c'; $a=~s/_+//g; }, 'y' => sub { $a='a _ b __ c'; $a=~ y/_//sd; } } ); __END__ Benchmark: timing 100000 iterations of s, y... s: 9 wallclock secs ( 7.18 usr + 0.00 sys = 7.18 CPU) @ 13 +927.58/s (n=100000) y: 2 wallclock secs ( 2.19 usr + 0.00 sys = 2.19 CPU) @ 45 +578.85/s (n=100000) Rate s y s 13928/s -- -69% y 45579/s 227% --

Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Replies are listed 'Best First'.
Re: (crazyinsomniac) Re: convert whitespaces to underscores
by Juerd (Abbot) on May 26, 2002 at 23:23 UTC

    (tr/// vs s///)

    It doesn't matter for this script as it doesn't matter for most scripts. This particular script is slow because of forking and filesystem changes. Changing the s/// to a tr/// won't increase the speed notably. Not even for a million MP3 files.

    s///g may not be the best way, but it is certainly not a bad way.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2019-05-21 16:31 GMT
Find Nodes?
    Voting Booth?
    Do you enjoy 3D movies?

    Results (135 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!