my @dispatch = (
[ sub { shift =~ m/test/ } => sub { action } ],
[ sub { shift == 2 } => sub { action } ],
[ sub { shift ge 'Hello' } => sub { action } ],
);
foreach my $case ( @dispatch ) {
if( $case->[0]($test_value) ) {
$case->[1](); # Action.
last;
}
}
####
my @dispatch = (
... same as above ...
);
$dispatch[ # In the table...
firstidx { $_->[0]($test_value) } @dispatch # do a lookup...
]->[1](); # and take action.
##
##
my @dispatch = (
...same as above ...
);
( first { $_->[0]($test_value) } @dispatch )->[1]();