aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Westerberg <drclaw@mac.com>2019-11-17 14:49:55 +1000
committerRuben Westerberg <drclaw@mac.com>2019-11-17 14:49:55 +1000
commit91627fd80424e001f5ce92332021d2af7b9c0dac (patch)
tree9e215ef4b3ee546e8bac10505aa62bdd5f6b7279
parent1bed72c489f813a382570b240392eac1c299fc55 (diff)
downloadperlweeklychallenge-club-91627fd80424e001f5ce92332021d2af7b9c0dac.tar.gz
perlweeklychallenge-club-91627fd80424e001f5ce92332021d2af7b9c0dac.tar.bz2
perlweeklychallenge-club-91627fd80424e001f5ce92332021d2af7b9c0dac.zip
Added perl5 solutions ch-1 and ch-2
-rwxr-xr-xchallenge-034/ruben-westerberg/perl5/ch-1.pl21
-rwxr-xr-xchallenge-034/ruben-westerberg/perl5/ch-2.pl13
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-034/ruben-westerberg/perl5/ch-1.pl b/challenge-034/ruben-westerberg/perl5/ch-1.pl
new file mode 100755
index 0000000000..b139e90fe8
--- /dev/null
+++ b/challenge-034/ruben-westerberg/perl5/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+#Demonstate array and hash slicing
+my @array=(0,1,2,3,4,5,6,7,8,9);
+my %hash=(a=>0, b=>1, c=>2, e=>3);
+print "Original Array: ". join(", ",@array) ."\n";
+print "Original Hash ". join(", ",%hash) ."\n";
+
+print "Slicing Array with a range [0..3]: ";
+print join(",", @array[0..3]),"\n";
+
+print "Slicing Array with duplicate index [0,0]: ";
+print join(",", @array[0,0]),"\n";
+
+
+print "Slicing hash into another hash %hash{qw<a b>}: ";
+print join(",", %hash{qw<a b>}),"\n";
+
+print 'Slicing hash in to value array @hash{qw<a b>}: ';
+print join ",", @hash{qw<a b>};
+
diff --git a/challenge-034/ruben-westerberg/perl5/ch-2.pl b/challenge-034/ruben-westerberg/perl5/ch-2.pl
new file mode 100755
index 0000000000..ea0577cd35
--- /dev/null
+++ b/challenge-034/ruben-westerberg/perl5/ch-2.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+
+#Build dispatch table of functions
+my @dispatch=map { my $i=$_;sub { templateSub($i)}} 1..10;
+
+#Randomly execute entries in the the table
+&{$dispatch[int rand @dispatch]} for (@dispatch);
+
+#Template function
+sub templateSub {
+ print "Hello from sub @_\n"
+}
+