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:
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?&{$ref}();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to call a sub-routine ref
by greengaroo (Hermit) on Oct 22, 2012 at 14:27 UTC |