Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: min and max in a hash of hash

by wwe (Friar)
on Jul 12, 2010 at 16:30 UTC ( #849041=note: print w/ replies, xml ) Need Help??


in reply to Re: min and max in a hash of hash
in thread min and max in a hash of hash

Hi ikegami, could you enlighten me what is wrong on using List::Util? the following code works fine, after I corrected the hash provided:

foreach my $y (sort keys %Year) { my $min_y = List::Util::min values %{ $Year{$y} }; print "min of [$y] is [$min_y]\n"; }
Edit: this works for sure only if you doesn't care about the month of the min/max value.


Comment on Re^2: min and max in a hash of hash
Download Code
Re^3: min and max in a hash of hash
by ikegami (Pope) on Jul 12, 2010 at 22:28 UTC

    That will give you the minimum value for each year. The OP wanted just the overall minimum. If he doesn't need the y/m of the minimum, then he could use

    use List::Util qw( min max ); my $min = min map { min values %{$Year{$_}} } keys %Year; my $max = max map { max values %{$Year{$_}} } keys %Year;

    Update: Fixed s/values/keys/ as per reply.

      hi, slight correction

      use List::Util qw( min max ); my $min = min map { min values %{$Year{$_}} } keys %Year; my $max = max map { max values %{$Year{$_}} } keys %Year;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://849041]
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: (21)
As of 2013-05-21 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (436 votes), past polls