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?
(note the extra parenthesis in order to enforce list context)while ( ($book_id) = $sth->fetchrow_array() ) { $booklist_1{$book_id} = 1; }
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} = {}; }
|
|---|