in reply to Calling func named in string

For this, you don't even need to turn strict off (search the documentation for &):
for my $funcname (@FuncList) { $JumpTbl{$funcname} = \&$funcname; }
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Calling func named in string
by MikeL (Acolyte) on Dec 16, 2024 at 19:41 UTC

    Ooh, aah! Thank you for pointing this out!

    By changing to use the backslash-ampersand, I do get references. I would have sworn I'd tried this, but that it didn't work, I guess not. Anyways, here's what I've got now...

    use strict; + use warnings; my @FuncList = qw(TestSub1 TestSub2); my @CallFunc = map { \&$_ } @FuncList; my %JumpTbl = map { $_ => \&$_ } @FuncList; $CallFunc[1](); $JumpTbl{'TestSub1'}(); exit; sub TestSub1 { print "TestSub1\n"; } sub TestSub2 { print "TestSub2\n"; }

    Output:

    TestSub2 TestSub1