in reply to Re^3: 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?
Here is part of my code (its the same as the one I post earlier but I change it to make it looks simpler to understand:
$variable1 = ''; print OUT1 "$first[0]\t$first[1]\t$first[2]\t"; for my $index1 (3..8) { my $ratio1 = sprintf( "%.4f%s", $numerator/$denominator,"\t"); #print OUT1 "$ratio1"; $variable1 = "$ratio1"; # problem with this line } print OUT1 "$variable1"; # print to textfile print OUT1 "\n";
I am trying to print out the output after it run finish the for loop 6 times (3 to 8). The data should arrange something like this:
Desired output (e.g.):
Instead, it print out only the last column:A98 0.98 123 4 4 4 4 4 4 A09 0.87 154 2 6 5 8 3 1 A12 0.12 873 6 1 2 4 7 0
so I change to this line by adding the "." to join the 6 columns togetherA98 0.98 123 4 A09 0.87 154 1 A12 0.12 873 0
and I get weird output like this:$variable1 .= "$ratio1"; # problem with this line
A98 0.98 123 4 4 4 4 4 4 A98 0.98 123 4 4 4 4 4 4 2 6 A98 0.98 123 4 4 4 4 4 4 2 6 4 A98 0.98 123 4 4 4 4 4 4 2 6 4 6 A98 0.98 123 4 4 4 4 4 4 2 6 4 6 1 ...
I know its got to do with the placement of the $variable1 .= "$ratio1"; ...but I have simply no idea how to go on and correct from there.
The reason for attempting to capture the values from the for loop is because I want to calculate my average and CV. This variable will then put into hashes with the first three columns and go thru filter to filter out based on certain conditions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How to store the output from foreach loop into variable/array without printing?
by hazylife (Monk) on Mar 13, 2014 at 10:14 UTC | |
|
Re^5: How to store the output from foreach loop into variable/array without printing?
by Anonymous Monk on Mar 13, 2014 at 10:11 UTC | |
by hellohello1 (Sexton) on Mar 14, 2014 at 02:03 UTC | |
by Anonymous Monk on Mar 14, 2014 at 03:08 UTC | |
by hellohello1 (Sexton) on Mar 14, 2014 at 06:19 UTC | |
by Anonymous Monk on Mar 14, 2014 at 06:45 UTC | |
|