in reply to Passing a sth to CGI form element methods

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)];

Replies are listed 'Best First'.
Re^2: Passing a sth to CGI form element methods
by agianni (Hermit) on Apr 11, 2007 at 14:43 UTC

    I'll take that as a vote for keeping it simple, and I think I agree. The popup_menu method doesn't buy us that much. The truth of the matter is that I don't expect this will buy us much. One of my colleagues is suggesting that we pass in statement handles instead of the data structures themselves and I wanted to see what reaction I got here. So far I'm getting the feeling that we should probably just leave well enough alone :)

    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'