Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Order a hash?

by atl (Pilgrim)
on Jul 20, 2000 at 20:24 UTC ( [id://23419]=note: print w/replies, xml ) Need Help??


in reply to Order a hash?

I'm wondering ... unless you do something with the hash after the foreach loop (not shown), why do you read everything into it in the first place?

You could iterate over the single lines of what the database returns (at least using DBI 1.12, don't know about pre-1.0-versions), therefore preserving the order generated by the database (your "order by" statement):

... $dbh = DBI->connect("DBI:mysql:$database:$hostname", $user, $password) +; $statement = "select ... order by ..."; $sth = $dbh->prepare($statement) or die "Can't prepare $statement: $dbh->errstr\n"; $rv = $sth->execute or die "can't execute the query: $sth->errstr\n"; my @row; while(@row = $sth->fetchrow_array) { # @row contains the individual columns # ... do work ... } $rc = $sth->finish; $rc = $dbh->disconnect;
8-)

Andreas

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://23419]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-28 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found