I do believe that the truly salient point is this:
There's one other misconception you seem to have that I'd like to clear up. You can't have a $b{foo}{bar} and have $b{foo} set to some unrelated value (such as 1). If there is a $b{foo}{bar}, then $b{foo} must somehow be a reference to a hash where you access ->{bar}. In your original code, that "reference" was "1", treated as a symbolic reference to %1. In the code I suggested, it's a hard reference to an anonymous hash that gets printed as 'HASH(0x8529f88)'.
This appears to be the real root of the problem. I started with a one-dimensional hash, then extended it to two dimensions. $booklist_1{$book_id} therefore becomes a reference to a hash and I can no longer use it the way I was trying to.
On this basis, I changed it to
and that works perfectly.while ($book_id = $sth->fetchrow_array()) { $booklist_1{$book_id}{'book_id'} = 1; }
In reply to Re^8: Why is my code assigning the last-retrieved value to all elements in my hash?
by punch_card_don
in thread Why is my code assigning the last-retrieved value to all elements in my hash?
by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |