bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
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++;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pushing a 'hash slice' to an AoH
by borisz (Canon) on Jun 11, 2004 at 16:45 UTC | |
|
Re: Pushing a 'hash slice' to an AoH
by Anonymous Monk on Jun 11, 2004 at 16:33 UTC | |
by bradcathey (Prior) on Jun 11, 2004 at 16:46 UTC | |
|
Re: Pushing a 'hash slice' to an AoH
by Roy Johnson (Monsignor) on Jun 11, 2004 at 20:35 UTC | |
|
Re: Pushing a 'hash slice' to an AoH
by eXile (Priest) on Jun 12, 2004 at 14:22 UTC | |
by bradcathey (Prior) on Jun 12, 2004 at 14:34 UTC |