I'm answering my own question, I got it figured out - I was making this much harder than necessary. In the following, I included line 16 which calls outside of the "no strict 'refs'", causing an error, so as to show that "strict refs" is operating normally outside of the block. Also, if you only want to call out a sub by a number, you don't need the JumpTbl hash, that's only needed to call it out by name:
use strict; + use warnings; my @FuncList = qw(TestSub1 TestSub2); my %JumpTbl = map { $_ => $_ } @FuncList; { no strict 'refs'; $JumpTbl{'TestSub2'}(); $FuncList[0](); } $JumpTbl{'TestSub1'}(); exit; sub TestSub1 { print "TestSub1\n"; } sub TestSub2 { print "TestSub2\n"; }
Output:
TestSub2 TestSub1 Can't use string ("TestSub1") as a subroutine ref while "strict refs" +in use at ./triv.pl line 16.
In reply to Re: Calling func named in string
by MikeL
in thread Calling func named in string
by MikeL
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |