rlk has asked for the wisdom of the Perl Monks concerning the following question:
I figured everone here is probably tired of hearing "why doesn't this work?", so I thought I'd ask "why does this work?" for a change.
In a recent node, I posted a piece of code similar to the following:
sub foo { print "In sub foo!" }; %bar = ( baz => \&foo ); $foo{baz}();
Now, this works, but btrott pointed out to me that $bar{baz} is a coderef, so the third line above should have been one of these two lines.
&{$bar{baz}}(); $bar{baz}->();
Now, both the Camel Book and perlref mention that the arrow operartor is optional between {}'s and []'s, (eg $foo{bar}->1->{baz} can be written as $foo{bar}1{baz})
However I can't find any documentation on automatic dereferencing of subroutine calls. Is this something that's lacking in the documentation, or am I missing something?
--
Ryan Koppenhaver, Aspiring Perl Hacker
"I ask for so little. Just fear me, love me, do as I say and I will be your slave."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: $foo{bar}-() vs. $foo{bar}()
by Carl-Joseph (Scribe) on Oct 07, 2000 at 10:58 UTC | |
by rlk (Pilgrim) on Oct 07, 2000 at 11:03 UTC | |
|
argh!
by rlk (Pilgrim) on Oct 07, 2000 at 11:00 UTC | |
by Ovid (Cardinal) on Oct 07, 2000 at 20:11 UTC | |