Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Why is my code assigning the last-retrieved value to all elements in my hash?

by karavelov (Monk)
on Jul 09, 2008 at 19:40 UTC ( [id://696539]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Why is my code assigning the last-retrieved value to all elements in my hash?
in thread Why is my code assigning the last-retrieved value to all elements in my hash?

I think the bug is here. Try to write something like
while ( ($book_id) = $sth->fetchrow_array() ) { $booklist_1{$book_id} = 1; }
(note the extra parenthesis in order to enforce list context)

or

while ( $book_id = $sth->fetchrow_arrayref() ) { $booklist_1{ $book_id->[0] } = 1; }

Code is not tested

Best regards

UPDATE:. I have overseen the kyle suggestion. It seems that the right code regarding the second loop will be:

while ( ($book_id) = $sth->fetchrow_array() ) { $booklist_1{$book_id} = {}; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found