in reply to Initializing a subroutine with the value of a variable
However, this calls "foo" as a class method, so the sub gets the classname as the first argument. If you dont want that, use a dispatch table.sub foo { print 'bar' } $var = 'foo'; main->$var;
%subs = ( 'foo' => \&foo, 'bar' => \&bar, # etc ); print $subs{$var}->($arg1, $arg2);
|
|---|