On Wed, Jun 18, 2008 at 20:02, Richard Lee <[EMAIL PROTECTED]> wrote:
> trying to understand closure and callback(bit over my head but)
>
> while I think i grasp most of the ideas from below program.. I don't think I
> understand why ( ) is needed in
>
> my $sum = $subs{$_}{GETTER}->( );
snip

You need them because $subs{$_}{GETTER} is code reference.  If you said

my $sum = $subs{$_}{GETTER};

then $sum would be the same reference.  ->() is one of the ways you
can deference (i.e. call) a code reference.  You could also say

my $sum = &{$subs{$_}{GETTER}};

but ->() is more modern.  You can also ditch the -> operator in
expressions like this one for the same reason you can ditch it with
other nested references, but many people would probably get annoyed
with you:

my $sum = $subs{$_}{GETTER}( );

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to