:)

Yes, i mentioned that i tend to avoid using hashes to store database result sets, but that doesn't mean that i avoid hashes in database code. One of my favorite tricks is to store the names of columns in an array and a hash:

my $sth = $dbh->prepare('select stdout,stdin from stderr'); $sth->execute; my @field = @{$sth->{'NAME'}}; my %field = map { $field[$_] => $_ } (0..$#field); my $rows = $sth->fetchall_arrayref();

Now i know what belongs where, but have other issues with your code, namely printing inside a sub like that i meant - storing the 'print' results in a string and returning that. How about transforming the data structure into another one and then having one printing subroutine? The obvious drawback is memory consuption, of course.

My other problem is sorting outside the database. I am sure there is at least one situation 'out there' that calls for it, but most of the time you should let the database do it.

But, good stuff none-the-less. I am not going to refute it. I'll leave that for princepawn, whom you didn't see coming. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Using hashes instead of arrays with database results by jeffa
in thread Using hashes instead of arrays with database results by trs80

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.