Or anytime you're talking about a named subroutine (my $bar = \&foo;) or using the GOTO &SUB form (goto &$bar;). There's still a few places that it's required. Another reason to use the ampersand version is to disable prototype checking, for those subroutines that are evil enough to use it without good reason.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] [d/l] [select] |
The use of &foo in \&foo has nothing to do with dereferencing. You're not calling foo.
Also, in goto &$bar; you aren't derefencing - it's the magical goto that jumps to the subroutine pointed to by $bar. If you were derefencing, you'd jump to the label that was returned by &$bar;. And that's what's happening if you do goto $bar->();. Or goto &$bar();.
Another reason to use the ampersand version is to disable prototype checking, for those subroutines that are evil enough to use it without good reason.
But that's a difference between foo() and &foo(). Again, that has nothing to do with dereferencing. It can't even do prototype checking when doing dereferencing, as prototype checking is done at compile time. The following code runs without errors - despite violent prototype violations:
!/usr/bin/perl
use strict;
use warnings;
my $ref = sub ($) {print "Hello, world\n"};
&$ref();
$ref->();
__END__
Neither the &$ref();, nor the $ref->(); is checked for its prototype. | [reply] [d/l] |
He knows they have nothing to do with dereferencing. He was contradicting the following completely false statement (which had nothing to do with dereferencing):
About the only place you'd need the ampersand version is if you're trying to get the current scope's @_ passed a la &somesub;. But that's really rare.
| [reply] |