in reply to Re: Perl at Rosetta Code, with one particular example
in thread Perl at Rosetta Code, with one particular example

Thanks for fixing the RC; it's slower; + RAM now at ~13.5 Mb vs. mine of ~10 Mb according to my crude measurements.

use strict; use warnings; use Benchmark 'cmpthese'; cmpthese -3, { am => sub { my ( @a, %h ); open my $fh, '<:raw', 'unixdict.txt' or die; while ( <$fh> ) { next unless length > 6; chomp; ( -1 != index $_, 'e' ) ? ( push @a, $_ ) : ( -1 != index $_, 'i' ) ? ( $h{ $_ } = 1 ) : 1 } close $fh; my ( @ret, $i ); exists $h{ $i = tr/e/i/r } and push @ret, sprintf "%30s %s\n", $_, $i for @a; @ret }, rc => sub { my $file = do { local (@ARGV, $/) = 'unixdict.txt'; <> }; my %i = map { tr/e/i/r => sprintf "%30s %s\n", $_, tr/e/i/r } $file =~ /^(?=.{6}).*e.*$/gm; @i{ split ' ', $file }; } } __END__ Rate rc am rc 25.2/s -- -65% am 71.1/s 182% --