in reply to Idiomatic way of getting from database result set to HTML::Template data structure?

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

  • Comment on Re: Idiomatic way of getting from database result set to HTML::Template data structure?
  • Download Code

Replies are listed 'Best First'.
Re: Re: Idiomatic way of getting from database result set to HTML::Template data structure?
by Anonymous Monk on Mar 29, 2004 at 16:04 UTC
    If I could use the Template::Toolkit, the whole thing would most certainly have been a view problem, and indeed a no-brainer.

    HTML::Template is a lot more constrained in that regard, coping only with variables, conditionals and iterators.

    Ta,
      You're missing the point. Sorting may be easier with TT, but H::T just prints out what you give it. Sort it before you hand it off to the View section. In other words, inflate your data, then sort it, then hand it off.

      ------
      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

        I'm not missing the point at all! The whole point of my question was getting the structure in a pre-sorted form the HTML::Template can use.