If you want the key that corresponds the the lowest value of a hash, instead of code like
my $lowest = min values $products_and_prices;
you'll want something like
my ($lowest) = sort {$products_and_prices->{$a} <=> $products_and_pric
+es->{$b}} keys $products_and_prices;
The parentheses create list context on the assignment, so that lowest gets assigned to the first list element, which is the item that was smallest. Of course, you could write something more efficient, and I haven't tested the above because you still haven't posted useful example code.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] [Watch: Dir/Any] [d/l] [select] |
kennethk, I was getting 'Not a Hash Reference' with that sort method, I have updated my code with a sample data structure. Sorry again.
UPDATE: With your method slightly modified, I got it:
my ($lowest) = sort {$products_and_prices->{$a} <=> $products_and_pric
+es->{$b}} keys @{$products_and_prices}[0];
| [reply] [Watch: Dir/Any] [d/l] |