aboutsummaryrefslogtreecommitdiff
path: root/challenge-033/javier-luque/perl6/ch-1.p6
blob: eca4c5fc42d8cbab1afc541ba4893a20b97aec2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Test: perl6 ch1.p6 example1.txt example2.txt
use v6.d;

sub MAIN (*@filenames) {
    my %counts;

    # Loop through each file
    for @filenames -> $filename {
        my $fh = $filename.IO.open orelse .die;

        # Increment count for each word char
        while (my $char = $fh.getc) {
            %counts{$char.lc}++ if ($char.lc ~~ /\w/);
        }
    }

    # Print each char and count
    for %counts.keys.sort -> $item {
        "%2s %5i\n".printf($item, %counts{$item});
    }
}