I don't like the %a = there. You're creating the hash inside the map, but then overwriting it with the values again. Messy messy. I'd stick with something like:perl -na0777e '%a = map {$_, ++$a{$_}} @F; print join("\n", (sort { $a +{$b} <=> $a{$a} } keys %a)[0..9]), "\n"' <filename>
perl -ne '$a{$_}++ for split; END { @a = sort { $a{$b} <=> $a{$a} } ke +ys %a; print "$_\n" for @a[0..9]; }' <filename>
-- Randal L. Schwartz, Perl hacker
In reply to RE: Word Counter
by merlyn
in thread Word Counter
by plaid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |