in reply to problem with removing space

s/ /_/g;
That's yer regex. You can write the rest of the script yourself by exploring PM for some tips.

Azatoth a.k.a Captain Whiplash

Make Your Die Messages Full of Wisdom!
Get YOUR PerlMonks Stagename here!
Want to speak like a Londoner?

Replies are listed 'Best First'.
Re: Problem with removing space (Benchmark s vs. tr)
by OeufMayo (Curate) on Apr 03, 2001 at 21:26 UTC

    For better performances you'd probably prefer to use a translation instead of a substitution.

    perl -MBenchmark -e 'timethese(1000000,{ "s" => "$_=qq(a a a a a a ); s/ /_/g", "tr" => "$_=qq(a a a a a a ); tr/ /_/", })' Benchmark: timing 1000000 iterations of s, tr... s: 15 wallclock secs (13.81 usr + 0.00 sys = 13.81 CPU) @ 72411.30/s (n=1000000) tr: 5 wallclock secs ( 4.38 usr + 0.00 sys = 4.38 CPU) @ 228519.20/s (n=1000000)
    <kbd>--
    my $OeufMayo = new PerlMonger::Paris({http => 'paris.mongueurs.net'});</kbd>
Re: Re: problem with removing space
by runrig (Abbot) on Apr 03, 2001 at 21:23 UTC