in reply to Word Counter

You wrote:
perl -na0777e '%a = map {$_, ++$a{$_}} @F; print join("\n", (sort { $a +{$b} <=> $a{$a} } keys %a)[0..9]), "\n"' <filename>
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 -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

Replies are listed 'Best First'.
RE: RE: Word Counter
by chromatic (Archbishop) on May 09, 2000 at 20:18 UTC
    How about a round of golf, merlyn? perl -ne '$a{$_}++ for split; END { print join "\n", (sort { $a{$b} <=> $a{$a} } keys %a)[0 .. 9]; } <filename>
      perl -lne '$a{$_}++ for split } print for (sort { $a{$b} <=> $a{$a} } keys %a)[0..9]; {' <filename> or even better: perl -lpe '$a{$_}++ for split } for ((sort { $a{$b} <=> $a{$a} } keys %a)[0..9]) {' <filename>