The List::Utils module is core, meaning that it is delivered and installed with any distribution of Perl. The List::MoreUtils probably needs to be installed from the CPAN.

And, yes, you should probably use them, but just in case you worry about how to do it in "pure Perl" (i.e. not using modules), which might be useful for learning purposes, this small session under the Perl debugger gives an idea on how you might do it:

DB<1> @array = qw/1 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 + 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3/; DB<2> while (@array) { $sum = 0; $sum += shift @array for 1..10; pri +nt "$sum\n";}; 10 40 20 30
A real life program would need to do a bit more error checking than that, but you've got the basic idea. Note that at the end, the array is empty, so that if you need to keep the array you would have to first do a copy of it.

In reply to Re^2: Nested for loop: Add arrays values in 1 set of 10 by Laurent_R
in thread Nested for loop: Add arrays values in 1 set of 10 by amitgsir

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.