aptom has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perlers,
I want to post-proces a Template Toolkit DBI call.
That is, push the values from the DBI query into a hash and then process the hash
E.g.
[% FOREACH row = query.execute() %] if(exists $hash{[% row.ITEMS %]}{ [% row.TYPE %] }){ $hash{ [% row.ITEMS %]}{[% row.TYPE %]}++; } else{ $hash{ [% row.ITEMS %]}{[% row.TYPE %]} = 1; [% END %]
Then I would iterate over the hash.
Anyone done something similar to this before?
Thanks,
Ap

Replies are listed 'Best First'.
Re: Postprocess Template Toolkit DBI Call
by sierpinski (Chaplain) on Aug 05, 2010 at 13:59 UTC
    Yes, I'm sure someone has done something similar before...

    I'm not sure I understand the reason for your posting. Are you having a problem or an error of some type? Are you looking for a better way to do it? Let us know what kind of response you're hoping for, and we might be able to help.
      Apologies for not being clear.
      What I'd like to do is push values returned from a DBI query within Template into a hash and then process that hash.
      I am unsure on how to do this.
      Thanks,
      Ap
        Taken me a few days but think I've nutter it out.
        [% sql_entries = query.execute() %] [% terms = {} %] [% FOREACH row IN sql_entries; terms.${row.LOCATION} = "${row.LOCID}"; END %] [% FOREACH row IN terms.keys %] [% row %]: [% terms.$row %] [% END %]

        Note: LOCATION and LOCID are columns returned from the query