in reply to Iterating hash of blessed hashes
In my opinion, a better use of reduce:
use List::Util qw( reduce ); my $highest_rated = reduce { $a->{Rating} >= $b->{Rating} ? $a : $b } grep $_->{Season} == $seasonnum, values %$hdata; my $banner_path = $highest_rated->{BannerPath};
Using procedural style instead,
my $highest_rated; for (values(%$hdata)) { next if $_->{Season} != $seasonnum; $highest_rated //= $_; if ($_->{Rating} > $highest_rated->{Rating}) { $highest_rated = $_; } } my $banner_path = $highest_rated->{BannerPath};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Iterating hash of blessed hashes
by BrowserUk (Patriarch) on Feb 17, 2011 at 09:13 UTC | |
by ikegami (Patriarch) on Feb 17, 2011 at 16:25 UTC |