in reply to Re: Re: Re: max value in a hash
in thread max value in a hash

Now another problem If you have a hash with multiple values for each key such as the following. How would you calculate the max for each key: Example
Keys value A 1 A 2 A 3 B 4 B 5 B 6
use strict; use warnings; use List::Util qw(first max); while(<INPUT2>){ (my $probeset_id, my $origin, my $probeseq, my $pip, my $gc, +my $affyscore) = split("\t", $_); push (@{$hash_F2_1{$origin}}, $pip); # This makes a hash of m +ultiple value for each probeset ID foreach my $origin (sort keys %hash_F2_1){ foreach my $position (@{$hash_F2_1{$origin}}){ my $max = max values %hash_F2_1; print "$origin\t$max\n"; } }
THIS CODE DOES NOT WORK!! Any Idea

Replies are listed 'Best First'.
Re^5: max value in a hash
by toolic (Bishop) on Sep 12, 2008 at 18:18 UTC
    Assuming you have a Hash-of-Arrays:
    use strict; use warnings; use List::Util qw(max); my %hoa = ( a => [(1..3)], b => [(4..6)] ); for (sort keys %hoa) { print "$_ ", max(@{$hoa{$_}}), "\n"; } __END__ a 3 b 6
      Thanks rsied1 It worked!!!