in reply to calling a sub using a variable's value
Your code will work if you switch off the stricture,
but that is usually not the best practice. Use hard references, as NetWallah suggests.{ no strict 'refs'; # the code }
If you must select a sub with a string, wrap up the hard references in a hash,
Props to you for using strict. It's a good habit and it paid off for you here.my %code = ( foo => \&foo, bar => \&bar, baz => sub { print 'baz here', $/ } ); my $pick = 'foo'; $code{$pick)();
After Compline,
Zaxo
|
|---|