Friday Perl Challenge

Jonathan McKeown jonathan at hst.org.za
Fri Apr 20 10:38:21 BST 2007


On Friday 20 April 2007 09:24, Chris Jack wrote:
> In one line. write a script to read stdin (or variable number of file
> arguments) that splits the input into words (non-whitespace consecutive
> characters), and outputs, sorted, each unique word and the number of times
> it occurs.

perl -alne 'map{$_++}@c{@F}}{print "$_ $c{$_}" for sort keys %c'

Ugly map in void context to avoid using foreach twice.

Jonathan


More information about the london.pm mailing list