aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2019-09-08 20:30:32 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2019-09-08 20:30:32 -0400
commit6c7a23d444d3cfc090246126b8863fe6352fb325 (patch)
tree953f377b7596d9596fc56cc781a820340d92f281
parent1e014901647c47d5a78ff75b16103ecb250d9680 (diff)
downloadperlweeklychallenge-club-6c7a23d444d3cfc090246126b8863fe6352fb325.tar.gz
perlweeklychallenge-club-6c7a23d444d3cfc090246126b8863fe6352fb325.tar.bz2
perlweeklychallenge-club-6c7a23d444d3cfc090246126b8863fe6352fb325.zip
Challenge 24 by Jaldhar H. Vyas - missing solution.
-rw-r--r--challenge-024/jaldhar-h-vyas/perl6/ch-2.p627
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-024/jaldhar-h-vyas/perl6/ch-2.p6 b/challenge-024/jaldhar-h-vyas/perl6/ch-2.p6
new file mode 100644
index 0000000000..98b7707e08
--- /dev/null
+++ b/challenge-024/jaldhar-h-vyas/perl6/ch-2.p6
@@ -0,0 +1,27 @@
+#!/usr/bin/perl6
+
+sub process($filename, %index) {
+ my $lineno = 0;
+
+ for $filename.IO.lines -> $line {
+ $lineno++;
+ for $line.words -> $word {
+ %index{$word}.push({ document => $filename, line => $lineno });
+ }
+ }
+}
+
+sub MAIN(*@ARGS) {
+ my %index;
+
+ for @*ARGS -> $filename {
+ process($filename, %index);
+ }
+
+ for %index.keys.sort -> $word {
+ $word.say;
+ for %index{$word}.sort({ %^a{'document'} cmp %^b{'document'} }) -> %entry {
+ say q{ }, %entry{'document'}, ' - ', %entry{'line'};
+ }
+ }
+}