On 9 August 2010 13:25, me @ <m...@psybermonkey.net> wrote: > Hi, Hi,
Not sure why you had to send this twice. I'm trying to pickup CGI web application programming using Perl, DBI & ... ... >>>> start of list.tt <<< > Content-type: text/html > > > [% PROCESS header %] > Form <strong>List</strong> > <p> > <ul> > [% FOREACH kar IN kars.values %] > <li>[% kar.reg_no %], [% kar.brand %], [% kar.cc %]</li> > [% END %] > </ul> > </p> > [% PROCESS footer %] >>>> end of list.tt <<< > > My question : > - I suppose the above code convert array into hash and pass it to TT, is > there any other way then this because I find that the line noise is a bit > too much. Line noise? What is it you want to cut out? You are iterating over the values of your hash. You don't need to specify values here, you could omit the values and, according to the TT man page[1] do: [% FOREACH kars %] <li>[% reg_no %]....</li> [% END %] > - I've read about some where on some website that arrays passing to TT > should always use array reference ($sth->fetchrow_arrayref) instead of the > above, using arrays ($sth->fetchrow_array). If this were to use array > reference, can someone show some codes to me so that i may check it out and > try to understand. I think you might be getting a bit confused here. TT requires references for it's parameters variable, so yes array, hash references (or any reference that returns a list) but that is different from how you retrieve data from the DBI. You turned that data into a hash of hash references when you did this: while (($reg_no, $brand, $cc) = $sth->fetchrow_array()) { $kar{$reg_no} = { reg_no => $reg_no, brand => $brand, cc => $cc } } If you want to use the DBI directly within TT then you should look at using the TT DBI plugin[2]. you may get more help on TT matter from the TT list[3]. Good luck, Dp. [1] http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH [2] http://search.cpan.org/~rehsack/Template-DBI-2.65/lib/Template/DBI.pod [3] http://mail.template-toolkit.org/mailman/listinfo/templates -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/