ler224 has asked for the wisdom of the Perl Monks concerning the following question:
__DATA__ U1 ID1 100 280 U1 ID1 137 250 U2 ID2 150 375 U1 ID2 100 100 U3 ID1 100 600 U9 ID3 137 200
orexample output: (Field[0]) U1 3 337 3 630 U2 1 150 1 375 U3 1 100 1 600 U9 1 137 1 200
I could do that by modifying: $fields[0] to 0 or 1. But I cannot figure out how to dynamically set the number of columns. I believe I may need something like this below, where I can loop for each column. And chose the columns (fields) that I want to use in an @column = (1,2,10,20).example output: (Field[1]) ID1 3 300 3 1130 ID2 2 250 2 475 ID3 1 137 1 200
I want to avoid the below, because then I need to write 2 lines of code for each column that I want to manipulate and it would make it harder to change the columns that I want.$res{$fields[0]}{$column}{instance}++; $res{$fields[0]}{$column}{volume} += $fields[$column];
$res{$fields[0]}{instance}++; $res{$fields[0]}{volume} += $fields[1]; $res{$fields[0]}{instance2}= (<insert code to count field[2]>) $res{$fields[0]}{volume2} += $fields[2];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Sum & Count column based data
by NetWallah (Canon) on Nov 15, 2013 at 04:05 UTC | |
by Anonymous Monk on Nov 21, 2013 at 18:22 UTC | |
|
Re: Perl Sum & Count column based data
by Kenosis (Priest) on Nov 15, 2013 at 04:17 UTC | |
|
Re: Perl Sum & Count column based data
by aaron_baugher (Curate) on Nov 15, 2013 at 04:34 UTC | |
|
Re: Perl Sum & Count column based data
by hdb (Monsignor) on Nov 15, 2013 at 07:12 UTC | |
|
Re: Perl Sum & Count column based data
by ig (Vicar) on Nov 15, 2013 at 03:54 UTC | |
|
Re: Perl Sum & Count column based data
by CountZero (Bishop) on Nov 15, 2013 at 07:08 UTC | |
|
Re: Perl Sum & Count column based data
by Anonymous Monk on Nov 15, 2013 at 03:30 UTC | |
|
Re: Perl Sum & Count column based data
by ler224 (Acolyte) on Nov 15, 2013 at 06:03 UTC | |
|
Re: Perl Sum & Count column based data
by ler224 (Acolyte) on Nov 21, 2013 at 19:16 UTC |