Perlseeker_1 has asked for the wisdom of the Perl Monks concerning the following question:
I have created a hash which takes value and store as mentioned below
Hash output
$VAR1 = [ 'AB', '1', 'Traverse' ]; $VAR2 = [ 'AB', '3', 'Traverse' ]; $VAR3 = [ 'CD', '2', 'Traverse' ]; $VAR4 = [ 'CD', '2', 'Traverse' ]; $VAR1 = [ 'JK', '1', 'Traverse1' ]; $VAR2 = [ 'JK', '3', 'Traverse1' ]; $VAR3 = [ 'KJ', '2', 'Traverse1' ]; $VAR4 = [ 'KJ', '2', 'Traverse1' ];
Output Expected
Traverse AB 4 CD 4 Subtotal 8 Traverse1 JK 4 KJ 4 Subtotal 8 Total 16
My code
my $size = scalar(@f); for ( my $i=0;$i<$size;$i++ ) { my $key = "$f[$i]->[0]"; $result{$key}->[0] += $f[$i]->[1]; }
i want output as mentioned below,I am expecting output as below
Traverse AB 4 CD 4 Subtotal 8 Traverse1 JK 4 KJ 4 Subtotal 8 Total 16
Thanks and regards
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: printing output on text file from file - perl
by mtmcc (Hermit) on Oct 15, 2013 at 15:57 UTC | |
|
Re: printing output on text file from file - perl
by Eily (Monsignor) on Oct 15, 2013 at 16:08 UTC | |
by Perlseeker_1 (Acolyte) on Oct 15, 2013 at 16:24 UTC | |
|
Re: printing output on text file from file - perl
by Kenosis (Priest) on Oct 15, 2013 at 17:13 UTC | |
|
Re: printing output on text file from file - perl
by kcott (Archbishop) on Oct 15, 2013 at 18:35 UTC | |
by Perlseeker_1 (Acolyte) on Oct 19, 2013 at 04:03 UTC | |
|
Re: printing output on text file from file - perl
by Generoso (Prior) on Oct 15, 2013 at 16:35 UTC |