in reply to Re: Sum of values in an array
in thread Sum of values in an array

I was surprised by my $total += $_->{COMP_TOTAL} for @pe_total; so I ran the code. No output generated so I modified the print to print "$^V >$total<"; which prints:

v5.16.3 ><

What is different about the way you are running the sample code? Different Perl verion maybe?

The B::Deparse of the summing line is:

(my $total += $$_{'COMP_TOTAL'}) foreach (@pe_total);

but my Perl foo isn't strong enough to decide if that means $total is local to the loop body or not. The result implies that it is, at least for this version of Perl.

Perl is the programming world's equivalent of English

Replies are listed 'Best First'.
Re^3: Sum of values in an array
by BrowserUk (Patriarch) on Sep 25, 2014 at 21:20 UTC

    You're right. I ran it in my REPL, thus globals; and added the my when posting (to encourage its use). Now corrected above. Thanks.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.