Bah, I botched the code portion, start with this code please
#!/usr/bin/perl -- ## by us ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; Main( @ARGV ); exit( 0 ); sub Main { UsedToBeJustDoWork(); } sub UsedToBeJustDoWork { my $full_data = [ ["M11", 0.1, 10, 24, 56, 77, 98, 72], ["M12", 0.3, 13, 44, 23, 45, 56, 11], ["M13", 0.4, 54, 23, 11, 25, 67, 91], ]; my $d_h = [ [ 24, 56, 77, 98, 72], [ 44, 23, 45, 56, 11], [ 23, 11, 25, 67, 91], ]; ## I don't know what you want here ## write it out as if using pencil and paper ## name the vars what you want ## make the program runnable ... like this my $these_first_row_avg = $$d_h[0][0] + $$d_h[0][1] + $$d_h[0][2] + + $$d_h[0][3] + $$d_h[0][4] / 4; my $these_second_row_avg = $$d_h[1][0] + $$d_h[1][1] + $$d_h[1][2] + + $$d_h[1][3] + $$d_h[1][4] / 4; my $these_third_row_avg = $$d_h[2][0] + $$d_h[2][1] + $$d_h[2][2] + + $$d_h[2][3] + $$d_h[2][4] / 4; ## you want these?? my $these_column_d_avg = $$d_h[0][0] + $$d_h[1][0] + $$d_h[2][0] / + 3; my $these_column_e_avg = $$d_h[0][1] + $$d_h[1][1] + $$d_h[2][1] / + 3; my $these_column_f_avg = $$d_h[0][2] + $$d_h[1][2] + $$d_h[2][2] / + 3; my $these_column_g_avg = $$d_h[0][3] + $$d_h[1][3] + $$d_h[2][3] / + 3; my $these_column_h_avg = $$d_h[0][4] + $$d_h[1][4] + $$d_h[2][4] / + 3; ## these are for your final data structure ## what do you want to have here my $these_first = [ $these_first_row_avg ]; my $these_second = [ $these_second_row_avg ]; my $these_third = [ $these_third_row_avg ]; my $final_output_wanted = [ $these_first, $these_second, $these_third, ]; dd( $final_output_wanted ); } ## end sub UsedToBeJustDoWork

In reply to Re^12: How to store the output from foreach loop into variable/array without printing? by Anonymous Monk
in thread How to store the output from foreach loop into variable/array without printing? by hellohello1

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.