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:
Thanks all!$events[$ctr]{'col1'} = $sqldata->[$i]{'col1'); $events[$ctr]{'col2'} = $sqldata->[$i]{'col2'); $events[$ctr]{'col3'} = $sqldata->[$i]{'col3'); $ctr++;
In reply to Pushing a 'hash slice' to an AoH by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |