My guess is there's a reference somewhere you're not expecting. For example, if %booklist_l is initialized this way:
my %booklist_l; @booklist_l{ @book_id_list } = ( { title => 'empty', update_id => 'missing' } ) x scalar @book_id_list;
...then every item in %booklist_l has the same reference to an "empty" record.
Also, DBI, when it returns things from fetchrow_hashref, always returns the same reference (as a performance optimization). As such, if you do this:
$booklist_l{ $book_id } = $sth->fetchrow_hashref;
...again, you'll have the same reference everywhere. In that case, you can get a copy of what it returns like this:
$booklist_l{ $book_id } = { %{$sth->fetchrow_hashref} };
That doesn't look like what you're doing, but I can't run your example code, so I'm suspicious.
Update: I think I didn't explain my suspicion very well. Each $booklist_l{ $book_id } is a reference to a hash. I suspect they're all the same reference. How that happened, I'm not sure, but I give a couple of possibilities above. An easy way to check whether they're all the same reference is to stringify them. Your ending debugging loop could be:
foreach $book_id (keys %booklist_1) { my $r = $booklist_l{$book_id}; print "XXX $book_id > $r->{'update_id'} -- from $r\n"; }
In reply to Re: Why is my code assigning the last-retrieved value to all elements in my hash?
by kyle
in thread Why is my code assigning the last-retrieved value to all elements in my hash?
by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |