in reply to How To Do This Better?
Now, that's many times faster than your original, and a fair bit shorter. I suspect it can be made faster still, though (is the slowdown produced by using s/// offset by the speedup on the next iteration, for instance?){ local $/ = undef; # Read everything in one go $_ = lc(<STDIN>); s/[^a-z]//g; # Get rid of nonalphabetic character +s for my $letter ('a'..'z') { my $count = s/$letter//g; # Magic! print "$letter = $count\n"; } }
|
|---|