in reply to Pull down menu using HTML::Template

Well, for starters, you are not structuring your data efficiently. You might take a lesson from the database concept of normalization. In a nutshell, when you are trying to represent more than one value in a variable (in this case, "sons") you should be seeing a red flag, or in Perlish terms, more hashes.

You are probably looking at a loop within a loop, using a more complete structure of an AoHoAoH's (think that's right), the outer loop being the "adults" and the inner loop being the "sons." Also, H::T requires a reference to an AoH for loops. Oh, and one more thing, your keys should be the same in each element of the array--below I show both Wife and Friend in each. Otherwise there's no way for the loop to differentiate between the two in the HTML (no logic available unless you are using H::T::Expr)

my $AoH = [ { 'Lead' => 'fred', 'Wife' => 'wilma', 'Friend' => 'barney', 'Son' => [ { 'name' => 'mike'}, { 'name' => 'jon' }, { 'name' => 'bill'} ], 'No' => '1', }, { 'Lead' => 'george', 'Wife' => 'jane', 'Friend' => 'sam', 'Son' => [ { 'name' => 'elroy'}, { 'name' => 'sam' }, { 'name' => 'bobby'} ], 'No' => '1', } ]; HTML: <tmpl_loop parents> <tmpl_var Lead> <tmpl_var Wife> <tmpl_var Friend> <tmpl_loop Son> <select> <option value="<tmpl_var Name>"><tmpl_var Name></option> </select> </tmpl_loop> </tmpl_loop>

Anyway, see the HTML::Template docs for all the glorious details.


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re^2: Pull down menu using HTML::Template
by sara2005 (Scribe) on Jan 31, 2007 at 21:42 UTC

    Works fine!!!

    I modified the code to create the data structure as suggested in your example.

    Thanks a lot.