blob: 70f6eedb41b3889c5ec1f501ecbd63ad5631c482 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
}
|