Re: [Templates] Perl to TT question
[prev]
[thread]
[next]
[Date index for 2004/10/28]
Tuesday, October 19, 2004, 10:45:19 PM, you wrote:
R> I have a Perl routine which does this:
R> my $count = 0;
while($sth->>fetchrow_arrayref) {
R> if ($count % 2) {
R> print "something";
R> }
R> else {
R> print "something else";
R> }
R> $count++;
R> }
R> Is this the equivalent?
R> [% count = 0;
R> WHILE ($sth->fetchrow_arrayref) %]
R> [% IF ($count % 2) %]
R> print "something";
R> [% ELSE %]
R> print "something else";
R> [% END %]
R> count++;
R> [% END %]
R> Just trying to wrap my head around converting it to TT format.
Look
http://www.template-toolkit.org/docs/plain/Modules/Template/Plugin/DBI.html
for details of DBI plugin usage.
Smth like this
[% USE DBI('dbi:driver:dbname', 'user', 'pass') %]
[% query = DBI.prepare('SQL QUERY HERE') %]
[% FOREACH sth = query.execute() %]
[% IF loop.index % 2 %]
something
[% ELSE %]
something else
[% END %]
[% END %]
--
Best regards,
lio mailto:lio@xx.xx
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
 |
Re: [Templates] Perl to TT question
lio 10:37 on 28 Oct 2004
|