Friday Perl Challenge

Luis Motta Campos luismottacampos at yahoo.co.uk
Fri Apr 20 12:19:57 BST 2007


On Apr 20, 2007, at 9:24 AM, 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.
>
> Bonus marks for not using
>
> 1)       cheat mechanisms (such as '||') which fudge the one line
> requirement
>
> 2)       round brackets
>
> 3)       the same perl function more than once
>

   Do I win extra points for using a /e regexp? :-)

perl -nle 's{\S+}{$w{$&}++;}eg}{print"$_,$w{$_}"for sort keys%w'

--
Luis Motta Campos (a.k.a. Monsieur Champs) is a software engineer,
Perl fanatic evangelist, and amateur {cook, photographer}




More information about the london.pm mailing list