Fellow Monasterians,
In response to a question I asked earlier, I'm learning to use CGI to write some HTML for me (within the context of HTML::Template). However, when working with the OPTGROUP, using code copied right out of CGI's doc on CPAN, I'm getting an error:
(3 in the code below).Undefined subroutine &main::optgroup called at dropdowntests.pl line X
Here is my Perl:
my $query = new CGI; my $opt = $query -> popup_menu( -name=>'menu_name', -values=>[qw/eenie meenie minie/, optgroup( -name=>'optgroup_name', -values => ['moe','catch'])], -labels=>{'eenie'=>'one', 'meenie'=>'two', 'minie'=>'three'}, -default=>'meenie'); my $template = HTML::Template->new( filename => '../dropdowntests.tmpl', die_on_bad_params => 1); $template->param( optiongroup => $opt); print "Content-type: text/html\n\n"; print $template->output();
I understand the what the Perl is seeing, but not sure why CGI is "allowing" it. Comments? Thanks.
Update: Solved. I started experimenting with different import functions and found that I could not just use the plain use CGI; and needed at least use CGI qw/:standard/;. To quote from the CGI doc:
To use the function-oriented interface, you must specify which CGI.pm routines or sets of routines to import into your script's namespace.
In reply to CGI and optgroup menus has error by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |