Count words


examples/hash/count_words.p6
#!/usr/bin/perl6
use v6;

my $filename = 'examples/words.txt';

my %counter;

my $fh = open $filename;
for $fh.lines -> $line {
    my @words = split /\s+/, $line;
    for @words -> $word {
        %counter{$word}++;
    }
}

for %counter.keys.sort -> $word {
    say "$word {%counter{$word}}";


Copyright 2006, 2007, 2008, 2009, 2010 Gabor Szabo http://szabgab.com/ Index | TOC
If you are interested in on-site trainings by the author, please contact me directly.

Online courses: