Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Counting variable initialization

by dragonchild (Archbishop)
on Mar 29, 2005 at 18:58 UTC ( [id://443233]=note: print w/replies, xml ) Need Help??


in reply to Counting variable initialization

You're asking the wrong question, which is the problem. You're asking "How do I simultaneously declare a variable and use it within a loop to sum a list?" You really want to ask "How do I sum the values in a loop and assign the result to a variable?"
use List::Util qw( reduce ); my $t = reduce { $a + $b } @list; # Or ... use List::Util qw( sum ); my $t = sum @list;

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://443233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-25 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found