List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 18 1999 4:46am
Subject:Re: $sth->fetchrow_hashref
View as plain text  
At 10:31 PM -0500 8/17/99, Jeff Urban wrote:
>No.  The order is unpredictable -- One thing about hashes (in Perl) is
>that the elements are stored in such a way that no matter how you created
>the hash, the elements will come out in an unpredictable order.  (It is
>possible to retrieve the elements of a hash in the same order that they
>were inserted using the Tie::IxHash module, but that's probably not
>necessary.)
>
>One thing you might do is Sort your hash or examine each element upon
>retrieval using $sth->{NAME}.  There are good examples of sorting in the
>Perl Cookbook (Recipe 5.9).
>
>foreach $key (sort keys %somehash) {
>  print "$key = $somehash{$key}";
>}


This won't reflect the order in which the columns were specified in the
SELECT statement, though -- if that's an important thing to preserve.
In that case $sth->{NAME} is better.

-- 
Paul DuBois, paul@stripped
Thread
$sth->fetchrow_hashreftoxalot18 Aug
  • Re: $sth->fetchrow_hashrefPaul DuBois18 Aug
  • Re: $sth->fetchrow_hashrefJeff Urban18 Aug
    • Re: $sth->fetchrow_hashrefPaul DuBois18 Aug
    • Re: $sth->fetchrow_hashrefSebastian Hoffmann18 Aug
      • Re: $sth->fetchrow_hashrefLuuk de Boer18 Aug
        • Re: $sth->fetchrow_hashrefUrb LeJeune18 Aug