#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |