We'd like to cut down on the size of the memory footprint of some of our applications and one of the worst offenders is the building of large popup menus.

...but I'd like to pass in a statement handle and have it iterate through the results to save on memory bloat.
I'm a bit curious. How many entries do you have in your pull down lists? How much memory are you considering memory bloat? Are you using CGI.pm before the call to popup_menu or is the memory bloat you are seeing include all of CGI.pm?

If the problem is CGI.pm - well then don't use CGI.pm. If the problem is the size of you pulldown lists - then you may not be able to do anything other than taking the drastic step of leaving the pulldowns as place holders - splitting on the place holders -- streaming the chunks of html down to server and generating the popup lists on the fly when you hit a place holder. But that is very drastic and in 10 years of web application development I have never seen a need to go to that extreme.

Personally I'd either generate and cache huge lists in external files so that I don't have to manipulate everything in memory all the time.

Or I'd just use Template Toolkit similar to the following:
my $template = ' <select name="foo"> [%- FOREACH row = sth.fetchrow_hashref %] <option value="[% row.id %]">[% row.text %]</option> [%- END %] </select> '; Template->process(\$template, {sth => $sth});


my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Re: Passing a sth to CGI form element methods by Rhandom
in thread Passing a sth to CGI form element methods by agianni

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.