Perl: the Markov chain saw 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.

Create A New User
Node Status?
node history
Node Type: note [id://848930]
help
Chatterbox?
 erix just did a 12 km-run. Slow, but unstoppable! [choroba]: My recent record is 10km in 1 hour :) [perldigious]: Nice erix... perldigious' legs are so sore from portaging his kayak from place to place last weekend he can barely hobble 12m. :-) [erix]: you're faster than me then :) [erix]: well, at the moment, that is :)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-05-24 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (184 votes). Check out past polls.