in reply to Initializing a subroutine with the value of a variable
That's why it's not allowed with use strict so you need to disable strict locally!
But this approach should only be the last possible choice!use strict; our $a="func"; sub func {print shift}; { no strict 'refs'; &$a(42); }
hollis solution is much cleaner and defining a dispatch table can be done in a very compact way:
my %dispatch=( func1 => sub { print shift }, func2 => sub { print 1+ shift }, ); $dispatch{func1}->(42);
|
|---|