From b3c1c4bc5430d2db5a60bac0fae6f4a687436ec0 Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Mon, 2 Sep 2019 14:14:14 -0600 Subject: Joelle's P6 solution to 24.2 --- challenge-024/joelle-maslak/perl6/ch-2.p6 | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 challenge-024/joelle-maslak/perl6/ch-2.p6 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(" ") }"; + } +} + + -- cgit