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} = {}; }