aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-024/joelle-maslak/perl6/ch-2.p636
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(" ") }";
+ }
+}
+
+