From 341b31c02bcaf84fb878f2e340b7e1c9a2e1a79e Mon Sep 17 00:00:00 2001 From: Steven Wilson Date: Wed, 13 Nov 2019 16:24:56 +0000 Subject: add week 34 task 2 solution --- challenge-034/steven-wilson/perl5/ch-2.pl | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 challenge-034/steven-wilson/perl5/ch-2.pl 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) ) }->(); + -- cgit