Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Hashes of Hash in perl

by 2teez (Priest)
on Apr 17, 2013 at 14:39 UTC ( #1029161=note: print w/ replies, xml ) Need Help??


in reply to Hashes of Hash in perl
in thread Perl Hash

Hi Rajsai2825,
I know you have been given a workable script, but I just want to point out that you can do all your "stuff" using just a hash and function unpack.
As shown below. (ofcourse, I wouldn't drop all the "jar of honey" on your laps!:))

use warnings; use strict; my %input; my $total; my $grand_total; while (<DATA>) { chomp; next if /^$/; my ( $k1, $k2, $k3, $k4, $k5 ) = unpack("x25 A10 A10 x1 A10 x1 A1 +x1 A5"); $total += $k4; $grand_total += $k5; push @{ $input{'summary'}{'Detial_Summary'}{$k1}{$k2}{$k3}{ ++$k4 +} }, $k5; } push @{ $input{'summary'}{'TOTAL'}{$total} }, $grand_total; use Data::Dump; dd \%input; __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

OUTPUT
{ summary => { Detial_Summary => { "EMC CHECK" => { " abcdefghi" => { AZ_checker => { 2 => [20.32, + "24.00"] } }, " KBCDEFGHI" => { AZ_checker => { 2 => ["10.00 +", "14.00"] } }, }, "EMC CHECK1" => { " abcdefghi" => { AZ_checker => { 2 => [20.59, + "24.00"] } }, " HGIJHKKIF" => { AZ_checker => { 2 => ["10.00 +", "14.00"] } }, }, }, TOTAL => { 8 => [136.91] }, }, }
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Hashes of Hash in perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-07-07 09:44 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 (88 votes), past polls