sub inflate { my ($results) = @_; my %data; foreach my $results (@$results) { my ($mag, $issue, $article) = @{$results}{qw( mag_name issue_n +um article )}; push @{$data{$mag}{$issue}}, $article; } foreach my $mag (keys %data) { $data{$mag}{article_loop} = map { issue_number => $_, article_loop => $data{$mag}{$_}, } keys %{$data{$mag}}; } return \%data; }
It doesn't preserve the order the issues for each magazine came back from the database, but sorting should be a view question, not a data retrieval question.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
In reply to Re: Idiomatic way of getting from database result set to HTML::Template data structure?
by dragonchild
in thread Idiomatic way of getting from database result set to HTML::Template data structure?
by davehodg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |