in reply to Re^2: Dereferencing code refs with & vs. ->()
in thread Dereferencing code refs with & vs. ->()
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__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Dereferencing code refs with & vs. ->()
by ikegami (Patriarch) on Sep 23, 2005 at 15:11 UTC | |
by Fletch (Bishop) on Sep 23, 2005 at 21:35 UTC |