Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

fw (8970)

  (email not shown publicly)

Journal of fw (8970)

Tuesday December 09, 2008
04:43 PM

First Perl6 program

[ #38055 ]
This one reads STDIN, counts words (here words are things between whitespace), and prints them sorted in descending order by occurrence.

my %words;

$*IN.lines.split(/\s+/).map: { %words{$_}++ };

for %words.pairs.sort: { $^b.value <=> $^a.value } -> $pair {
    say $pair

see also: this node at perlmonks

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.