perlquestion
Anonymous Monk
Hello,<br>
is there a way to conditionally execute a subroutine defined as hash value?<br>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.<br>Thanks<br><br><br>
<code>
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";
}
</code>
13