aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2019-09-08 18:56:54 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2019-09-08 18:56:54 -0400
commit1e014901647c47d5a78ff75b16103ecb250d9680 (patch)
treecee87aa5ff5cb7dab1c0c61c19bf87841886e0bb
parent75a3cc3367548220bbb2bcad6f2d7e52cc973a2d (diff)
downloadperlweeklychallenge-club-1e014901647c47d5a78ff75b16103ecb250d9680.tar.gz
perlweeklychallenge-club-1e014901647c47d5a78ff75b16103ecb250d9680.tar.bz2
perlweeklychallenge-club-1e014901647c47d5a78ff75b16103ecb250d9680.zip
Challenge 24 by Jaldhar H. Vyas
-rw-r--r--challenge-024/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-024/jaldhar-h-vyas/perl5/ch-1.sh1
-rwxr-xr-xchallenge-024/jaldhar-h-vyas/perl5/ch-2.pl34
-rwxr-xr-xchallenge-024/jaldhar-h-vyas/perl6/ch-1.sh1
4 files changed, 37 insertions, 0 deletions
diff --git a/challenge-024/jaldhar-h-vyas/blog.txt b/challenge-024/jaldhar-h-vyas/blog.txt
new file mode 100644
index 0000000000..5d7618bc99
--- /dev/null
+++ b/challenge-024/jaldhar-h-vyas/blog.txt
@@ -0,0 +1 @@
+https://www.braincells.com/perl/2019/09/perl_weekly_challenge_week_24.html
diff --git a/challenge-024/jaldhar-h-vyas/perl5/ch-1.sh b/challenge-024/jaldhar-h-vyas/perl5/ch-1.sh
new file mode 100755
index 0000000000..17e28cc422
--- /dev/null
+++ b/challenge-024/jaldhar-h-vyas/perl5/ch-1.sh
@@ -0,0 +1 @@
+perl -V
diff --git a/challenge-024/jaldhar-h-vyas/perl5/ch-2.pl b/challenge-024/jaldhar-h-vyas/perl5/ch-2.pl
new file mode 100755
index 0000000000..3946e4150a
--- /dev/null
+++ b/challenge-024/jaldhar-h-vyas/perl5/ch-2.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use 5.010;
+use English qw/ -no_match_vars /;
+
+sub process {
+ my ($filename, $index) = @_;
+ open my $fh, '<', $filename or die "$OS_ERROR!";
+ my $lineno = 0;
+ while (my $line = <$fh>) {
+ $lineno++;
+ my @words = split /\W+/msx, $line;
+ for my $word (@words) {
+ push @{$index->{$word}}, { document => $filename, line => $lineno };
+ }
+ }
+ close $fh or die "$OS_ERROR\n";
+}
+
+my %index;
+
+for my $file (@ARGV) {
+ process($file, \%index);
+}
+
+
+for my $word (sort keys %index) {
+ say $word;
+ for my $entry (sort { $a->{document} cmp $b->{document} } @{$index{$word}}) {
+ say q{ }, $entry->{document}, ' - ', $entry->{line};
+ }
+ } \ No newline at end of file
diff --git a/challenge-024/jaldhar-h-vyas/perl6/ch-1.sh b/challenge-024/jaldhar-h-vyas/perl6/ch-1.sh
new file mode 100755
index 0000000000..1c1dae18cf
--- /dev/null
+++ b/challenge-024/jaldhar-h-vyas/perl6/ch-1.sh
@@ -0,0 +1 @@
+perl6 -V