in reply to Passing a sth to CGI form element methods

What's probably a better solution than adding support for database statement handles would be the more generic approach of adding support for iterators. Then, you'd only have to check if the value for values is a code ref instead of checking its class.

The problem I see is that the popup is generated entirely in memory (and returned to be printed), so you're only going to save a fraction of the memory you could save.

  • Comment on Re: Passing a sth to CGI form element methods

Replies are listed 'Best First'.
Re^2: Passing a sth to CGI form element methods
by agianni (Hermit) on Apr 11, 2007 at 14:31 UTC
    What's probably a better solution than adding support for database statement handles would be the more generic approach of adding support for iterators...

    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.

    The problem I see is that the popup is generated entirely in memory (and returned to be printed), so you're only going to save a fraction of the memory you could save.

    Actually, won't it save me about 2/3 of the memory? I'm passing in an arrayref and a hashref anyway and generating another data structure. If I never have to pass in the first two, won't that save me on the memory that would be used for their storage?

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

      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.