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:
Neither the &$ref();, nor the $ref->(); is checked for its prototype.!/usr/bin/perl use strict; use warnings; my $ref = sub ($) {print "Hello, world\n"}; &$ref(); $ref->(); __END__
In reply to Re^3: Dereferencing code refs with & vs. ->()
by Anonymous Monk
in thread Dereferencing code refs with & vs. ->()
by doran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |