A function call is returning a struct that Data::Dumper says looks like this (I've elided some entries):
I want to iterate over the entries and extract the BannerPath with the highest Rating for a given Season. What's the best approach? My solution feels a bit clunky...{ + '771271' => bless( { + 'Language' => 'en', + 'Rating' => '10.0000', + 'BannerType2' => 'seasonwide', + 'Season' => '1', + 'BannerPath' => 'seasonswide/79349-1-3. +jpg', 'BannerType' => 'season', + 'RatingCount' => '1' + }, 'DBM::Deep::Hash' ), + '586831' => bless( { + 'Language' => 'en', + 'Rating' => '5.5000', + 'BannerType2' => 'seasonwide', + 'Season' => '4', + 'BannerPath' => 'seasonswide/79349-4-3. +jpg', 'BannerType' => 'season', + 'RatingCount' => '2' + }, 'DBM::Deep::Hash' ), + '771301' => bless( { 'Language' => 'en', 'Rating' => '10.0000', 'BannerType2' => 'seasonwide', 'Season' => '4', 'BannerPath' => 'seasonswide/79349-4.jp +g', 'BannerType' => 'season', 'RatingCount' => '1' }, 'DBM::Deep::Hash' ) };
my $hdata = <call that creates the struct>; my ($rating, $bwurl); my @keys = keys %$hdata; foreach my $id (@keys) { my $hr2 = $hdata->{$id}; if (($hr2->{Season} == $seasonnum) && ($hr2->{Rating} > $rating)) +{ $rating = $hr2->{Rating}; $bwurl = $hr2->{BannerPath}; } }
In reply to Iterating hash of blessed hashes by ron7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |