aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-09-03 10:36:50 +0100
committerGitHub <noreply@github.com>2019-09-03 10:36:50 +0100
commitb902dc2a6b4022ef5c32c70667732f5373a5789b (patch)
treedb8befccc8ae52fa1b7e59ad19b4091e2f1b449e
parenta5666406241dd3b724a5cad110f857699c838dc4 (diff)
parentb3c1c4bc5430d2db5a60bac0fae6f4a687436ec0 (diff)
downloadperlweeklychallenge-club-b902dc2a6b4022ef5c32c70667732f5373a5789b.tar.gz
perlweeklychallenge-club-b902dc2a6b4022ef5c32c70667732f5373a5789b.tar.bz2
perlweeklychallenge-club-b902dc2a6b4022ef5c32c70667732f5373a5789b.zip
Merge pull request #594 from jmaslak/joelle-24-2-2
Joelle's P6 solution to 24.2
-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(" ") }";
+ }
+}
+
+