in reply to Strict, strings and subroutines
my $sub = \&{'do_'.$type}; $sub->();
Is perfectly legal. But if you don't want the extra variable
(\&{'do_'.$type})->();
will work too. But the benefit of using the variable is that you can check that the sub actually exists with
my $sub = \&{'do_'.$type}; die "Unknown sub 'do_$type'" unless defined(&$sub);
|
---|