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.


In reply to Re^3: Passing a sth to CGI form element methods by ikegami
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.