Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: min and max in a hash of hash

by ikegami (Pope)
on Jul 12, 2010 at 06:12 UTC ( #848930=note: print w/ replies, xml ) Need Help??


in reply to min and max in a hash of hash

my ($max_y) = my ($min_y) = keys(%Year); my ($max_m) = my ($min_m) = keys(%{ $Year{$max_y} }); my $max = $Year{$max_y}{$max_m}; my $min = $Year{$min_y}{$min_m}; for my $y (keys(%Year)) { my $Month = $Year{$y}; for my $m (keys(%$Month)) { my $v = $Month->{$m}; if ($v < $min) { $min = $v; $min_y = $y; $min_m = $m; } elsif ($v > $max) { $max = $v; $max_y = $y; $max_m = $m; } } }

Update: I was initialising $max_y twice instead of initialising $min_m. Fixed.


Comment on Re: min and max in a hash of hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-07-13 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (250 votes), past polls