D. Bolliger wrote: > Chas Owens am Freitag, 6. April 2007 13:27: >>On 4/6/07, D. Bolliger <[EMAIL PROTECTED]> wrote: >> >>>$ perl -nle 'print join " ", map ucfirst, map lc, split' < in.txt > >>>out.txt >>There is no need to have multiple maps and the @ARGV/<> trick handles >>files as well as stdin, so there is no need to use < >> >>perl -lne 'print join " ", map { ucfirst lc } split' in.txt > out.txt > > You're right of course; your corrected version is not only more elegant and > perlish, but also - what a surprise ;-) - significantly faster. > > (I wondered how much: > > Rate twomaps onemap > twomaps 13003/s -- -26% > onemap 17668/s 36% -- > > including assignement of the test data to $_ for split (~1250000/s), > excluding print)
Yes it is faster, but... $ perl -e' use Benchmark q[cmpthese]; my $wordlist = qx[cat /usr/share/dict/words]; cmpthese -10, { twomaps => q{ join " ", map ucfirst, map lc, split " ", $wordlist }, onemap => q{ join " ", map ucfirst( lc ), split " ", $wordlist }, subst => q{ ( my $x = $wordlist ) =~ s/(\S+)/\L\u$1/g; $x }, }; ' Rate twomaps onemap subst twomaps 1729492/s -- -13% -38% onemap 1981233/s 15% -- -30% subst 2811473/s 63% 42% -- John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/