http://www.perlmonks.org?node_id=1000324


in reply to Re^2: How to call a sub-routine ref
in thread How to call a sub-routine ref

Did you actually test that code?

$ cat greengaroo.pl use strict; my $ref = sub { print "Hello World!\n"; }; # Both are equivalent $ref->(); &{ref}(); # But which one is best? That is the question! $ perl greengaroo.pl Hello World! Undefined subroutine &main::ref called at greengaroo.pl line 9.

your second call fails.

If you fix this by rewriting it thusly:

&{$ref}();
there is still the open question of "which is better?" From a readability standpoint I'd vote for the latter rather than the former. Others may disagree but that is the essence of TIMTOWTDI. If you feel there may be a performance issue involved here have you tried profiling the code?


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg