aboutsummaryrefslogtreecommitdiff
path: root/challenge-034
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2019-11-13 16:24:56 +0000
committerSteven Wilson <steven1170@zoho.eu>2019-11-13 16:24:56 +0000
commit341b31c02bcaf84fb878f2e340b7e1c9a2e1a79e (patch)
tree59adf7d05c7e6fcf8578f1e5c67f0b7e631583bc /challenge-034
parent15274eaec83534f5100535badd209e36f4f6f463 (diff)
downloadperlweeklychallenge-club-341b31c02bcaf84fb878f2e340b7e1c9a2e1a79e.tar.gz
perlweeklychallenge-club-341b31c02bcaf84fb878f2e340b7e1c9a2e1a79e.tar.bz2
perlweeklychallenge-club-341b31c02bcaf84fb878f2e340b7e1c9a2e1a79e.zip
add week 34 task 2 solution
Diffstat (limited to 'challenge-034')
-rw-r--r--challenge-034/steven-wilson/perl5/ch-2.pl34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-034/steven-wilson/perl5/ch-2.pl b/challenge-034/steven-wilson/perl5/ch-2.pl
new file mode 100644
index 0000000000..441163a79f
--- /dev/null
+++ b/challenge-034/steven-wilson/perl5/ch-2.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-11-13
+# Week: 034
+# Task #2
+# Contributed by Dave Cross
+# Write a program that demonstrates a dispatch table.
+
+use strict;
+use warnings;
+use feature qw/ say /;
+
+my %dispatch_table = (
+ 0 => \&bop_it,
+ 1 => \&twist_it,
+ 2 => \&bash_it,
+ 3 => \&pull_it,
+ 4 => \&flick_it,
+ 5 => \&spin_it,
+ 6 => \&shake_it,
+ 7 => \&try_harder,
+);
+
+sub bop_it { say "Bob it!" }
+sub twist_it { say "Twist it!" }
+sub bash_it { say "Bash it!" }
+sub pull_it { say "Pull it!" }
+sub flick_it { say "Flick it!" }
+sub spin_it { say "Spin it!" }
+sub shake_it { say "Shake it!" }
+sub try_harder { say "Try harder!" }
+
+$dispatch_table{ int( rand(8) ) }->();
+