aboutsummaryrefslogtreecommitdiff
path: root/challenge-034
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-11-16 10:50:09 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-11-16 10:50:09 +0000
commit060e1cdd1339642ddc270b6600339f7d94442296 (patch)
tree5b746c78372814aa39426b950249076a93ae07da /challenge-034
parent2960845ff5cc96326f78248c1c2cf075c49ceaa4 (diff)
downloadperlweeklychallenge-club-060e1cdd1339642ddc270b6600339f7d94442296.tar.gz
perlweeklychallenge-club-060e1cdd1339642ddc270b6600339f7d94442296.tar.bz2
perlweeklychallenge-club-060e1cdd1339642ddc270b6600339f7d94442296.zip
- Added solutions by E. Choroba.
Diffstat (limited to 'challenge-034')
-rwxr-xr-xchallenge-034/e-choroba/perl5/ch-1.pl36
-rwxr-xr-xchallenge-034/e-choroba/perl5/ch-2.pl36
2 files changed, 72 insertions, 0 deletions
diff --git a/challenge-034/e-choroba/perl5/ch-1.pl b/challenge-034/e-choroba/perl5/ch-1.pl
new file mode 100755
index 0000000000..70f6eedb41
--- /dev/null
+++ b/challenge-034/e-choroba/perl5/ch-1.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+my @keys = qw( not_this_one
+ this_one
+ this_one_too
+ it_was_enough );
+
+my %hash = (not_this_one => 'not selected',
+ this_one => 'selected first',
+ this_one_too => 'selected second',
+ it_was_enough => 'not selected either');
+
+my %dispatch = (show_array_slice => \&show_array_slice,
+ show_hash_slice => \&show_hash_slice,
+ show_index_value_slice => \&show_index_value_slice);
+
+my $what_to_show = shift;
+my $action = $dispatch{$what_to_show}
+ || sub { die "Unknown action $what_to_show!\n" };
+$action->();
+
+sub show_array_slice {
+ say for @keys[1, 2];
+}
+
+sub show_hash_slice {
+ say for @hash{ @keys[1, 2] };
+}
+
+sub show_index_value_slice {
+ my %selected = %hash{ @keys[1, 2] };
+ say for values %selected;
+}
diff --git a/challenge-034/e-choroba/perl5/ch-2.pl b/challenge-034/e-choroba/perl5/ch-2.pl
new file mode 100755
index 0000000000..70f6eedb41
--- /dev/null
+++ b/challenge-034/e-choroba/perl5/ch-2.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+my @keys = qw( not_this_one
+ this_one
+ this_one_too
+ it_was_enough );
+
+my %hash = (not_this_one => 'not selected',
+ this_one => 'selected first',
+ this_one_too => 'selected second',
+ it_was_enough => 'not selected either');
+
+my %dispatch = (show_array_slice => \&show_array_slice,
+ show_hash_slice => \&show_hash_slice,
+ show_index_value_slice => \&show_index_value_slice);
+
+my $what_to_show = shift;
+my $action = $dispatch{$what_to_show}
+ || sub { die "Unknown action $what_to_show!\n" };
+$action->();
+
+sub show_array_slice {
+ say for @keys[1, 2];
+}
+
+sub show_hash_slice {
+ say for @hash{ @keys[1, 2] };
+}
+
+sub show_index_value_slice {
+ my %selected = %hash{ @keys[1, 2] };
+ say for values %selected;
+}