Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: Difference between tr// and s///?

by Limbic~Region (Chancellor)
on Feb 06, 2004 at 16:45 UTC ( [id://327136]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Difference between tr// and s///?
in thread Difference between tr/// and s///?

davido,
You are correct as the following modified code shows:
#!/usr/bin/perl use strict; use warnings; use Benchmark qw(:all); my $length = (int rand 100) + 100; my @char = ( 'a' .. 'c' , '+' , 'd' .. 'f' ); my $string; $string .= $char[ int rand 7 ] for 0 .. $length ; my $count = -5; my $results = timethese ( $count, { 'transliterate' => sub { my $foo = $string; $foo =~ tr/ ++/ /; }, 'substitution' => sub { my $bar = $string; $bar =~s/\+ +/ /g; }, }, 'none' ); cmpthese( $results ) ; __END__ Rate substitution transliterate substitution 124624/s -- -84% transliterate 784349/s 529% --
Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2024-04-23 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found