diff options
| author | Joelle Maslak <jmaslak@antelope.net> | 2019-09-02 14:14:14 -0600 |
|---|---|---|
| committer | Joelle Maslak <jmaslak@antelope.net> | 2019-09-02 14:14:14 -0600 |
| commit | b3c1c4bc5430d2db5a60bac0fae6f4a687436ec0 (patch) | |
| tree | b9eb752423bccf47dbd85ad4521fd031aa3af936 | |
| parent | 6bfbf4b0a4b60a35654abac0259e7229bd5f96cc (diff) | |
| download | perlweeklychallenge-club-b3c1c4bc5430d2db5a60bac0fae6f4a687436ec0.tar.gz perlweeklychallenge-club-b3c1c4bc5430d2db5a60bac0fae6f4a687436ec0.tar.bz2 perlweeklychallenge-club-b3c1c4bc5430d2db5a60bac0fae6f4a687436ec0.zip | |
Joelle's P6 solution to 24.2
| -rwxr-xr-x | challenge-024/joelle-maslak/perl6/ch-2.p6 | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-024/joelle-maslak/perl6/ch-2.p6 b/challenge-024/joelle-maslak/perl6/ch-2.p6 new file mode 100755 index 0000000000..b8c687ee3a --- /dev/null +++ b/challenge-024/joelle-maslak/perl6/ch-2.p6 @@ -0,0 +1,36 @@ +#!/usr/bin/env perl6 +use v6; + +# This is the first one where I wrote a P5 solution before the P6 solution. +# +# It's also the only time the P6 output differs from the P5 output, +# although both meet the requirement of the challenge. +# +# Difference: Perl 6 IO.words splits differently than Perl 5 split /\W+/ + +sub MAIN(+@files) { + my %docs; + + # Read the files, seperating out the words. Sadly no parallelism + # here, I don't have a Perl6 module for doing simultanious file + # reads of large files. :( + for @files -> $fn { + %docs{$fn} = $fn.IO.words.unique; + } + + # Build the index + my %index; + for %docs.keys.sort -> $fn { + for @(%docs{$fn}) -> $word { + %index{$word} = [] unless %index{$word}:exists; + %index{$word}.push: $fn; + } + } + + # Output the index + for %index.keys.sort -> $word { + say "$word: { %index{$word}.join(" ") }"; + } +} + + |
