 Welcome to the Monastery  Re: subroutine refs  by broquaint
(Abbot) on Nov 30, 2007 at 18:19 UTC
( #654158=note: print w/ replies, xml ) Need Help??  in reply to
subroutine refs  You can safely create a reference to a
subroutine by name and the execute that e.g  use strict; sub
dynamic { print "Mmm, dynamic.\n"; } my $name = 'dynamic'; my
$subref = \&$name; &$subref();   Comment on Re: subroutine refs
Download Code Re^2: subroutine refs by blokhead (Monsignor) on
Nov 30, 2007 at 18:50 UTC     I find this very surprising. But I
checked it and it apparently works.      Why does this give an
error:      use strict; sub dynamic { print "hello\n"; } my
$name = "dynamic"; &$name();     .. and yet this is ok? (they
differ only in the last line)     use strict; sub dynamic {
print "hello\n"; } my $name = "dynamic"; &{ \&$name }();
Before seeing this, I would have bet anything that the &{\&{ ...
}} operation was absolutely the same as &{...} (barring weird
action-at-a-distance caused by tying, overloading, etc).