Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Summing Variables in foreach loop

by tobyink (Abbot)
on Jan 30, 2014 at 14:57 UTC ( #1072685=note: print w/ replies, xml ) Need Help??


in reply to Re: Summing Variables in foreach loop
in thread Summing Variables in foreach loop

A more normal way to use reduce would be to use the + operator in there, not +=. Using += could give the impression that the variable $a can be usefully modified within the block.

say reduce { $a + count_zeros($cgs,$b) } 0, <DATA>;
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name


Comment on Re^2: Summing Variables in foreach loop
Select or Download Code
Re^3: Summing Variables in foreach loop
by ikegami (Pope) on Jan 31, 2014 at 17:29 UTC
    A even more normal way would be avoid reduce entirely :)
    say sum 0, map count_zeros($cgs,$_), <DATA>;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2014-07-22 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (128 votes), past polls