in reply to Re^2: Passing a sth to CGI form element methods
in thread Passing a sth to CGI form element methods

I definitely like the idea of that, although I'm not likely going to write a CPAN module for this right now, so I don't think I would implement it with quite that much generality.

It's actually quite simple. Here's the difference:

while (my $ar = $sth->fetch()) { my $item = $ar->[0]; ... }

vs

sub make_sth_iterator { my ($sth) = @_; return sub { my $ar = $sth->fetch(); return $ar ? $ar->[0] : (); }; } my $iter = make_sth_iter($sth); # Parens around $item required. Without, # them an $item with value "" or "0" # will exit the loop prematurely. while (my ($item) = $iter->()) { ... }

Actually, won't it save me about 2/3 of the memory?

Well, 2/3 is a fraction :) but I think it might be less than that. The HTML text is more verbose than the data, and you probably have two copies of the HTML text in memory during the concatenation, but it's true that Perl variables have a lot of overhead. I'm not sure why you'd eliminate a hash.

Frankly, I'm concerned about your site's user experience. If the HTML is truly big enough to be worrisome on the server side, it's big enough to be worrisome on the client side.