IMO, the only time there is a reason to use & is if you get or call coderef, for example:
sub foo() { print "hi\n"; } my $x = \&foo; &$x();
The main time that you can use, which you absolutely should not in most cases, is to call a subroutine that has a prototype that sets the default behavior to a different one from the standard one. I mean, some prototypes allow you to reinterpret the list of arguments, for example, converting the @array and %hash specifications to links. Thus, sub will expect these reinterpretations to occur, and if you do not go to any length necessary to simulate them manually, sub will receive input data that are very different from those expected.
I think that basically people are trying to tell you that you are still writing in Perl 4 style, and now we have a much cleaner and more enjoyable thing called Perl 5.
In terms of performance, there are various ways in which Perl optimizes the subtitles that & lose, and one of the main ones is nesting constants.
There is also one circumstance where using & provides a performance advantage: if you redirect the foo(@_) with foo(@_) . Using &foo infinitely faster than foo(@_) . I would not recommend it if you have not finally found through profiling that you need this micro-optimization.
chaos Aug 28 '09 at 14:35 2009-08-28 14:35
source share