aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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'};
+ }
+ }
+}