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

    ++ your use of values. But you missed (your own) trick with grep in your procedural version:

    my ($rating, $bwurl) = 0; foreach my $subhash ( grep $_->{Season} == $seasonnum, values %$hdata +) { if( $subhash->{Rating} > $rating){ $rating = $subhash->{Rating}; $bwurl = $subhash->{BannerPath}; } }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I didn't miss, I was avoiding functional-style functions including grep. But by all means, mix and match to your liking.