in reply to Variable Sub Calls

I just tried this from the command line:
my $name = "do"; sub do { print "I am doing it\n"; } &$name;
It printed "I am doing it". There is more than one way to do it:
my $name = "do"; sub do { print "I am doing this now\n"; } $name->();
Notice that since both methods use symbolic references, they fail under use strict;. Another approach is:
$name = \& {"main::$name"}; &$name;
That depends on being in the main package, however. It does work under use strict.

A better approach might be building a hash of references to subroutines:

sub foo { print "Doing foo (whatever that means)\n"; } sub bar { print "Now doing bar (isn't this fun?)\n"; } my %sub_table = ( 'foo' => \&foo, 'bar' => \&bar, ); foreach ( qw (foo bar foobar ) ) { $sub_table{$_}->(); }
Nicer, isn't it?