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>

In reply to Pull down menu using HTML::Template by sara2005

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.