Gunnar Hjalmarsson said:
which directs you to:
"If you want to map strings between lower/upper cases, see
perlfunc/lc and perlfunc/uc"
out of interest, I did this:
#!/usr/bin/perl -w
use strict;
use Benchmark;
my $text='aBcDeFgHiJkLmNoPqUsTuVwXyZ';
my $result;
timethese(1000000, {
'lc' => sub {$result=lc($text)},
'tr' => sub {($result = $text)=~ tr/A-Z/a-z/;},
});
and got this:
Benchmark: timing 1000000 iterations of lc, tr...
lc: 0 wallclock secs ( 1.67 usr + 0.00 sys = 1.67 CPU)
@ 598802.40/s (n=1000000)
tr: 3 wallclock secs ( 2.40 usr + 0.00 sys = 2.40 CPU)
@ 416666.67/s (n=1000000)
which makes lc look quite a bit quicker. If I change it so
my $text='aBcDeFgHiJkLmNoPqUsTuVwXyZ' x 100;
I get:
Benchmark: timing 1000000 iterations of lc, tr...
lc: 64 wallclock secs (46.09 usr + 0.00 sys = 46.09 CPU)
@ 21696.68/s (n=1000000)
tr: 78 wallclock secs (55.29 usr + 0.00 sys = 55.29 CPU)
@ 18086.45/s (n=1000000)
And, of course, lc knows about locale where tr doesn't...
big