http://www.perlmonks.org?node_id=1080736

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
is there a way to conditionally execute a subroutine defined as hash value?
In the example below I get both subroutines executed, while I'd like to only execute one of them based on the value of $test.
Thanks


use strict; my $calls = { A => \&print_A(), B => \&print_B(), }; my $test = 'A'; $calls->{$test}; sub print_A { print "\nA\n"; } sub print_B { print "\nB\n"; }