Didn't mean to make it sounds like I'm an advocate for HT over TT2. I recognize the power TT2 provides, and I like what you can do with it. Just wish you could pass it arrays directly from Perl.

My MySQL query looks like this:

# issue query my $sth = $dbh -> prepare("SELECT uid, fname, lname FROM users") || &b +ail_out("Error: cannot prepare DB query"); $sth -> execute() || &bail_out("Error: cannot execute DB query");

The following loop yields an array with all relevant keys and values as individual elements. The results are printed to the terminal for testing:

while (@rray = $sth -> fetchrow_array) { $row{uid} = $rray[0]; $row{fname} = $rray[1]; $row{lname} = $rray[2]; push @rows, %row; } foreach (@rows) { print "$_\n"; }

This next variation is an attempt to build a hash instead of an array. It only builds one column (lname) from the table at this time. Keys are defined as records.

while (@rray = $sth -> fetchrow_array) { $record = "record_$i"; $hash{$record} = $rray[1]; $i += 1; } my ($key, $value); while (($key, $value) = each(%hash)) { print "key = $key, value = $value\n"; }

The two pieces of code above work. Finally, however, my attempt to build a HoH is failing. Here is what I have so far:

while (@rray = $sth -> fetchrow_array) { $record = "record_$i"; $hash1{fname} = $rray[1]; $hash2{$record} = %hash1; $i += 1; } while (($key, $value) = each(%hash2)) { print $hash2{$value} -> {fname}; }

There are obviously some problems here. Can you offer me some guidance?

Thanks!


In reply to Re^4: Best way to send records to the browser? by Perobl
in thread Best way to send records to the browser? by Perobl

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.