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:

Undefined subroutine &main::optgroup called at dropdowntests.pl line X
(3 in the code below).

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.


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

In reply to CGI and optgroup menus has error by bradcathey

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.