sara2005 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I running out of ideas to create a pull down by reading a data structure ( Array of Hashes ) and would appreciate some help/ ideas from fellow monks.
Data Structure:
my @AoH = ( { Lead => "fred", Friend => "barney", Son => "", No => "1", }, { Lead => "george", Wife => "jane", Son => "elroy|sam|bobby", No => "2", } );
In the present form, I am able to display the 'Sons' in the input text field but I want to have a pulldown menu if an array element has more than one name in the 'Son' field . For example, the 2nd element in the array of hashses has "elroy|sam|bobby", which I would lke to have as a pulldown.
Thanks
The code:
#! /usr/bin/perl -wT use strict; use warnings; use CGI qw/:standard :delete_all :escapeHTML :html3 :all/; use HTML::Template; # Get the data as array of hashes my $show_vars = get_data( ); print header; my $template = HTML::Template->new( filename => 'temp.tmpl' ); $template->param( show_vars => $show_vars ); print $template->output(); # subroutine to create the data structure sub get_data{ my @AoH = ( { Lead => "fred", Friend => "barney", Son => "", No => "1", }, { Lead => "george", Wife => "jane", Son => "elroy|sam|bobby", No => "2", } ); return ( \@AoH ); }
Template file :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Example</title> </head> <body> <table cellpadding="0" cellspacing="0" border="0" align="center" > <tmpl_loop name="show_vars"> <tr><td><hr /></td></tr> <tr valign="top" align="center"> <td ><a><tmpl_var name="Lead"></a> </td> </tr> <tr><td><br /></td></tr> <tr><td > <a>Son: </a><input type="text" name="<tmpl_var name="No">_<tmpl_var na +me="Son">" value="<tmpl_var name="Son">" /> </td> </tr> <tr><td><br /></td></tr> <tr><td><hr /></td></tr> <!-- Commented to hide from display <tr><td > <a>Friend: </a><input type="text" name="<tmpl_var name="No">_<tmpl_var + name="Friend">" value="" /> </td> </tr> <tr><td > <a>Wife: </a><input type="text" name="<tmpl_var name="No">_<tmpl_var n +ame="Wife">" value="" /> </td></tr> --> </tmpl_loop> </table> </body> </html>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pull down menu using HTML::Template
by bradcathey (Prior) on Jan 31, 2007 at 03:08 UTC | |
by sara2005 (Scribe) on Jan 31, 2007 at 21:42 UTC | |
|
Re: Pull down menu using HTML::Template
by jesuashok (Curate) on Jan 31, 2007 at 02:26 UTC | |
by sara2005 (Scribe) on Jan 31, 2007 at 02:46 UTC |