Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: HoH and accumulation

by djbiv (Scribe)
on Jan 28, 2004 at 22:17 UTC ( [id://324815]=note: print w/replies, xml ) Need Help??


in reply to Re: HoH and accumulation
in thread HoH and accumulation

thank you for your post! however trying to implement your second solution I am failing to see how this is adding the common keys within my HoH? I am using strict and warnings, the code above was just a snip from the entire program. Here is the code I threw in and played with.
my %total; my %subhash; foreach my $subhash (values %all_files) { foreach my $key (keys %$subhash) { my $junk = $total{$key} + $subhash{$key}; print "$junk\n"; } }
the results of adding this to total the values for the common keys always results in '0'? I have also tried creating a AoH instead but still have problems getting the correct accumalation... Here is the code for that.
for my $i ( 0 .. $#AoH ) { for my $role (sort keys %{ $AoH[$i] } ) { my $tcount = $AoH[$i]{$role} + $AoH[$i]{$role}; print "$role=$tcount\n"; } }
either way what I would like to accomplish is for each common key within the hash (either below the main array or main hash) accumalate the value for common keys...? maybe I'm just brain dead at this point from looking at it too long... thanks...

Replies are listed 'Best First'.
Re: Re: Re: HoH and accumulation
by tilly (Archbishop) on Jan 29, 2004 at 16:32 UTC
    I'm sorry, that was due to a typo on my part (I did warn that the code was untested).

    You need to write $subhash->{$key} and not $subhash{$key} because you need to dereference the scalar $subhash, not access %subhash. (As I note in my update, strict.pm catches this kind of bug for you.)

    If this fix confuses you, then I'd highly recommend reading references quick reference.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found