:) I think we should hae done fewer columns ...

So next step would be, instead of doing  my $ratio1_1_1... (pencil and paper), write a function to create that array (like a real array not named scalars)

Which I did , I replicated your program using functions

What I did was try a few different nested loops (counter), and compare the numbers to yours (what you typed)

It took like 8 permutations to get the numbers to match

sub makeRatio { my( $d_h ) = @_; my $rows = $#$d_h ; ## last index of array my $columns = $#{ $d_h->[0] }; ## last index of first row my @ratio; for my $six ( 0 .. $columns ){ for my $tre ( 0 .. $rows ){ for my $tri ( 0 .. $rows ){ ## for visual matching printf 'my $ratio%d_%d_%d = $$d_h[%d][%d] / $$d_h[%d] +[%d];'."\n", 1+$six, 1+$tri, 1+$tre, $tri, $six, $tre, $six, ;;; $ratio[ $six ][ $tri ][ $tre ] = $$d_h[ $tri ][ $six ] + / $$d_h[ $tre ][ $six ] ; } } } return \@ratio ; }

Naturally this is 0 indexed since programmers count from 0 (I was not tempted to change $ARRAY_BASE )

Then I turned more of your stuff into arrays slowly so that when writing functions I can compare/verify numbers .... should have done 2 rows 2 colums, whew :)

Now it wasn't too huge of a deal to compare what you got (what is expected) with what I got using my eyes, but once you come up with a function like I did, you should write a test for it, ...

 

Does this help you or would you like to see more?

Anything "click" for you after seeing makeRatio ? What clicked

Would you like to try writing the next function that makes use of \@ratio?

Or would you like to see the rest of my program (makeRatioAvg and makeFinal) ?


In reply to Re^14: 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.