An optimisation for you using map:

Replace the following

my @loop_data = (); my @keys = (); my @values = (); # incidentally, the "my %hash" on the next line should be just "%hash" while ((my $key, my $value) = each my %hash) { push(@keys, $key); push(@values, $value); } while (@keys and @values) { my %row_data; $row_data{KEY} = shift @keys; $row_data{VALUE} = shift @values; push(@loop_data, \%row_data); }
with...
my @loop_data = map { { KEY => $_, VALUE => $hash{$_} } } keys %hash;
map is a way to build lists from lists. in this case you can use it to iterate through the keys of %hash and create a hashref for each key/value pair to be stored in @loop_data.

Don't be confused by the { { ... } } syntax though - map likes a block (i.e. map { ... } list) or a single expression (i.e. map expression, list - notice the comma) but since you want hashrefs ({})we have to use a block or it will get confused when you put a comma after. Maybe I just confused you even more - RTFM and you should see what I mean.

Hope this helps.

Update

Regarding your actual question I think if you put the loop inside the <table></table> around the rows then it'll all be in the same table - is that what you were asking? Sorry, I'm feeling a bit thick today!

<table width=400 border=1 cellspacing=0 cellpadding=0> <TMPL_UNLESS SHOW_ALL_LOOP> <tr> <td> Nothing to see here folks, move along! </td> </tr> </TMPL_UNLESS> <TMPL_LOOP SHOW_ALL_LOOP> <tr> <td valign=top bgcolor=#dddddd> <b>Key</b>:&nbsp;<TMPL_VAR NAME="KEY"> <b>Value</b>:&nbsp;<TMPL_VAR NAME="VALUE"> </td> </tr> </TMPL_LOOP> </table><br>

Update 2

Check out DB_File::Lock for obvious reasons.

Update 3

For your second question you could just put the template vars in separate table cells:

<td valign=top bgcolor=#dddddd> <b>Key</b>:&nbsp;<TMPL_VAR NAME="KEY"> </td> <td> <b>Value</b>:&nbsp;<TMPL_VAR NAME="VALUE"> </td>
   larryk                                          
perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

In reply to map can help you by larryk
in thread How can I display DBM entries in an HTML table? (Revised) by bladx

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.