It seems like you're wanting a symbolic reference to refer to a lexical scalar (a my variable), which it can't directly. If, instead of 'my' you were using 'our', you could use the symbolic reference:
perl -E 'our $p = sub { 1 }; my $q = "p"; say $$q->();'
...but then your 'our' variable is a package global, and you're mucking around in the symbol table, which may be counterindicated for maintainability.
Couldn't this problem be solved with real refs and a hash table used as a dispatch table?
perl -E 'my %dispatch = ( p => sub { 1 } ); my $q = "p"; say $dispatch +{$q}->();'
Dave
In reply to Re: Invoking a string reference to a anonymous subroutine
by davido
in thread Invoking a string reference to a anonymous subroutine
by Superfox il Volpone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |