in reply to Re: Re: Re: Re: Re: string manipulation
in thread string manipulation
Also, since the $data is set in the sub it will be reset every pass. As well, you can just set up the benchmark like this and avoid having perl eval a sub call in a string:
timethese ( $count, { 'Method One S' => sub { my $data = 'foo-bar-baz'; $data =~ s/-/_/g; } 'Method Two TR' => sub { my $data = 'foo-bar-baz'; $data =~ tr/-/_/; } } );
Not a big deal but it may save you some typing in the future. Your way has the benefit of being easy to run the subs once and test their output, tho...
BTW, I moronically goofed my test string too... =)
--
$you = new YOU;
honk() if $you->love(perl)
|
|---|