in reply to Re^2: extract only smallest numbers
in thread extract only smallest numbers
Couple of things first.
Now you have some of the problems fixed. Now you need to test what's in the hash and $code.use strict; use warnings; open FILE, $my_file or die "Can't open $my_file\n"; my %hash; while (<FILE>) { my ($name, $code) = split(/\t/); }
One thing to remember is, that if you have not assigned a value to the hash for that key you'll get undef returned, which evaluates to 0 numerically. Since you are looking for the lowest number you'll want avoid the undef. So check the value from your hash with defined first. If you see that it is not defined, then you know to assign the value of $code whatever it is.
If you have a value defined then check to see whats larger# Still untested if ( !defined( $hash{$name} ) ) { $hash{$name} = $code; }
# Still untested if ( !defined( $hash{$name} ) or $code < $hash{$name} ) { $hash{$name} = $code; }
|
|---|