Fellow monasterians,

Using data from a MySQL table, I'm setting up an an AoH for a HTML::Template loop. I start by selecting all the columns because I need a couple 'non-displayable' columns for testing a condition. If the condition is met I want to assign just a few of the key/value pairs of the successful array element to the H::T loop's AoH.

Here's what I have based on something is saw in the Cookbook, pg 105, but is obviously wrong. Can something like this even work?

my $stmt = "SELECT * FROM table WHERE ... #execute... my $sqldata = $sth->fetchall_arrayref({}); my @events; for my $i ( 0 .. $#$sqldata ) { if ( $sqldata->[$i]{'col5'} eq $sqldata->[$i]{'col8'} ) { push ( @events, $sqldata->[$i]{'col1', 'col2', 'col3'} ); } } my $template = HTML::Template->new( filename => 'some.tmpl' ); $template -> param( events => \@events ); #etc...

or am I resigned to:

$events[$ctr]{'col1'} = $sqldata->[$i]{'col1'); $events[$ctr]{'col2'} = $sqldata->[$i]{'col2'); $events[$ctr]{'col3'} = $sqldata->[$i]{'col3'); $ctr++;
Thanks all!

—Brad
"A little yeast leavens the whole dough."

In reply to Pushing a 'hash slice' to an AoH by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.