Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Hashes of Hash in perl

by hdb (Prior)
on Apr 17, 2013 at 11:10 UTC ( #1029119=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Hashes of Hash in perl
in thread Perl Hash

I do not understand why you have not followed advice given in earlier thread but here is your code cleaned somewhat and running. Pls state what you want to achieve.

use strict; use warnings; my %output; while (my $line = <DATA>){ chomp $line; my @field = split /\s+/, $line; my $fulllookupKey = $field[1]."\t". $field[2]."\t". $field[3]."\t +".$field[4]."\t".$field[5]; my $RescatKey = $field[0]; my $RessubcatKey = $field[1]; my $MasterSrkey = $field[2]; $output{$RescatKey}{$RessubcatKey}{$fulllookupKey}->[0] += $field[ +6]; $output{$RescatKey}{$RessubcatKey}{$fulllookupKey}->[1] += $field[ +7]; } for my $k1 (sort keys %output){ print "$k1\n"; for my $k2 ( sort keys %{ $output{$k1} } ) { print "\t$k2\n"; for my $k3 ( sort keys %{ $output{$k1}{$k2} } ) { my $Source = substr($k3,15,100); print "\t\t$Source $output{$k1}{$k2}{$k3}->[0] +\t$output{$k1}{$k2}{$k3}->[1]\n"; print "\t\t$Source\t TOTAL \t$output{$k1}{$k2} +{$k3}->[1]\t$output{$k1}{$k2}{$k3}->[0]\n"; } } } __DATA__ Summary Detial_Summary EMC CHECK abcdefghi AZ_checker 1 20.32 Summary Detial_Summary EMC CHECK abcdefghi AZ_checker 1 24.00 Summary Detial_Summary EMC CHECK KBCDEFGHI AZ_checker 1 10.00 Summary Detial_Summary EMC CHECK KBCDEFGHI AZ_checker 1 14.00 Summary1 Detial_Summary1 EMC CHECK1 abcdefghi AZ_checker 1 20.59 Summary1 Detial_Summary1 EMC CHECK1 abcdefghi AZ_checker 1 24.00 Summary1 Detial_Summary1 EMC CHECK1 HGIJHKKIF AZ_checker 1 10.00 Summary1 Detial_Summary1 EMC CHECK1 HGIJHKKIF AZ_checker 1 14.00


Comment on Re^3: Hashes of Hash in perl
Download Code
Replies are listed 'Best First'.
Re^4: Hashes of Hash in perl
by Rajsai2825 (Novice) on Apr 17, 2013 at 14:14 UTC
    Hi, I have incorporated the advice given earlier. but i want to achive the output as below.
    Summary................................................ Detial_Summary................................... EMC CHECK abcdefghi AZ_checker 2 44.32 EMC CHECK KBCDEFGHI AZ_checker 2 24.00 EMC CHECK TOTAL 4 64.32 EMC CHECK1 abcdefghi AZ_checker 2 44.59 EMC CHECK1 HGIJHKKIF AZ_checker 2 24.00 EMC CHECK1 TOTAL 4 68.59 Detial_Summary TOTAL 8 132.91 Summary TOTAL 8 132.91
    The output what i am getting now:
    Summary................................................ Detial_Summary................................... EMC_CHECK abcdefghi AZ-Chandler 44.32 +2 EMC_CHECK abcdefghi AZ-Chandler TOTAL + 44.32 2 EMC_CHECK KBCDEFGHI AZ-Chandler 24.00 +2 EMC_CHECK abcdefghi AZ-Chandler TOTAL 24.00 + 2
    but i want output as below:
    Summary................................................ Detial_Summary................................... EMC_CHECK abcdefghi AZ-Chandler 44.32 +2 EMC_CHECK KBCDEFGHI AZ-Chandler 24.00 +2 EMC_CHECK TOTAL 68.32 4 Detial_Summary TOTAL 68.32 4 Summary TOTAL 68.32 4

      What about my proposal below?

        The Input Data:...............
        Summary Detailed_Summary EMC_CHECK cycleai00 chanlder 2 +08.592 1 Summary Detailed_Summary EMC_CHECK cycleai00 chanlder 3 +74.863 1 Summary Detailed_Summary EMC_CHECK cakiyaa00 chjkslyh 1. +821 1 Summary Detailed_Summary EMC_CHECK cakiyaa00 chjkslyh 8. +094 1 Summary Detailed_Summary EMC_CHECK chjkiya00 hkjkssas +6.623 1 Summary Detailed_Summary Lekatic chandana-s1 sraidnama 409.982 1 Summary Detailed_Summary Lekatic chandana-s1 sraidnama 304.887 1 Summary Detailed_Summary Lekatic chandana-s2 sraidnama 633.845 1 Summary Detailed_Summary Lekatic chandana-s2 sraidnama 340.582 1 Summary Detailed_Summary Lekatic chandana-s3 sraidnama 13.074 1 <code> The Output I am getting now after incorporating your proposal:........ +. <code> Summary Detailed_Summary EMC_CHECK cycleai00 AZ-Chandler 208.592 + 1 208.592 1 EMC_CHECK cycleai00 AZ-Chandler 208.592 + 1 TOTAL 1 208.592 EMC_CHECK cycleai00 AZ-Chandler 374.863 + 1 374.863 1 EMC_CHECK cycleai00 AZ-Chandler 374.863 + 1 TOTAL 1 374.863 EMC_CHECK cakiyaa00 NC-Charlotte 1.821 + 1 1.821 1 EMC_CHECK cakiyaa00 NC-Charlotte 1.821 + 1 TOTAL 1 1.821 EMC_CHECK cakiyaa00 NC-Charlotte 8.094 + 1 8.094 1 EMC_CHECK cakiyaa00 NC-Charlotte 8.094 + 1 TOTAL 1 8.094 EMC_CHECK chjkiya00 NY-NewYork 6.623 + 1 6.623 1 EMC_CHECK chjkiya00 NY-NewYork 6.623 + 1 TOTAL 1 6.623 Lekatic chandana-s1 PA-Levittown 304.887 1 304. +887 1 Lekatic chandana-s1 PA-Levittown 304.887 1 + TOTAL 1 304.887 Lekatic chandana-s2 PA-Levittown 409.982 1 409. +982 1 Lekatic chandana-s2 PA-Levittown 409.982 1 + TOTAL 1 409.982 Lekatic chandana-s2 PA-Levittown 340.582 1 340. +582 1 Lekatic chandana-s2 PA-Levittown 340.582 1 + TOTAL 1 340.582 Lekatic chandana-s2 PA-Levittown 633.845 1 633. +845 1 Lekatic chandana-s2 PA-Levittown 633.845 1 + TOTAL 1 633.845 Lekatic chandana-s3 PA-Levittown 13.074 1 13.0 +74 1 Lekatic chandana-s3 PA-Levittown 13.074 1 + TOTAL 1 13.074
        The Output what i want to achive:.............
        Summary Detailed_Summary Lekatic chandana-s2 sraidnama 2 974.427 Lekatic chandana-s1 sraidnama 2 714.869 Lekatic chandana-s3 sraidnama 1 13.074 Lekatic TOTAL 5 1702.37 EMC_CHECK cycleai00 chanlder 1 6.623 EMC_CHECK cakiyaa00 chjkslyh 2 583.455 EMC_CHECK chjkiya00 hkjkssas 2 9.915 EMC_CHECK TOTAL 5 599.993 Detailed_Summary TOTAL 10 2302.363 Summary TOTAL 10 2302.363 Grand TOTAL 20 5684.684
        My code:
        while (chomp(@field = split (/\t/, <RPTFILE>))) { my $fulllookupKey = $field[1]."\t". $field[2]."\t". $field[3]."\t +".$field[4]."\t".$field[5]; my $RescatKey = $field[0]; my $RessubcatKey = $field[1]; my $MasterSrkey = $field[2]; if (exists($output{$RescatKey}{$RessubcatKey}{$fulllookupKey})) + { $output{$RescatKey}{$RessubcatKey}{$fulllookupKey}->[0] += $fie +ld[6]; $output{$RescatKey}{$RessubcatKey}{$fulllookupKey}->[1] += $fie +ld[7]; } else { $output{$RescatKey}{$RessubcatKey}{$fulllookupKey}->[0] = $fiel +d[6]; $output{$RescatKey}{$RessubcatKey}{$fulllookupKey}->[1] = $fiel +d[7]; } } for my $k1 (sort keys %output){ print "$k1\n"; for my $k2 ( sort keys %{ $output{$k1} } ) { print "\t$k2\n"; for my $k3 ( sort keys %{ $output{$k1}{$k2} } ) { my $Source = substr($k3,16,100); print "\t\t$Source $output{$k1}{$k2}{$k3}->[0]\t$output{$k1}{$k2} +{$k3}->[1]\n"; print "\t\t$Source\t TOTAL \t$output{$k1}{$k2}{$k3}->[1]\t$output +{$k1}{$k2}{$k3}->[0]\n"; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029119]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (17)
As of 2015-07-29 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls