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."
In reply to $foo{bar}-() vs. $foo{bar}() by rlk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |