in reply to Re^13: How to store the output from foreach loop into variable/array without printing?
in thread How to store the output from foreach loop into variable/array without printing?
:) 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) ?
|
|---|