Syntactic Confectionery Delight | |
PerlMonks |
Re: Summing Up Array Elements By Groupby fullermd (Priest) |
on Jan 21, 2009 at 08:51 UTC ( [id://737778]=note: print w/replies, xml ) | Need Help?? |
For another alternate approach, first roll up the groups of 3 into array refs, then sum them up:
Thus we end up with:
By itself, it's a pretty roundabout version of what ivancho did above. But if you can use the grouping in other places in the program, it can be useful to group them up like that early on. Of course, if you don't, you skip the extra step and it collapses down to
which is just another way of writing ivancho's second version.
In Section
Seekers of Perl Wisdom
|
|