in reply to Adding an AoH to an AoH
You are storing multiple references to the same variable into your structure, but you meant to store references to different arrays.
for my $i ( 0 .. $#$proj ) { my $time = $dbh->selectall_arrayref($stmt, {Slice => {}}, $project_ +id); my @users; # Create a new array every pass through the loop. for my $j ( 0 .. $#$time ) { push @users, $time->[$j]; } $proj->[$i]{'users'} = \@users; }
By the way, undef @users; is also a bug, since it clears both @users and @{ $proj->[$i]{'users'} } since they're the same variable.
Update: The above code can be simplified to
for my $i ( 0 .. $#$proj ) { my $time = $dbh->selectall_arrayref($stmt, {Slice => {}}, $project_ +id); $proj->[$i]{'users'} = $time; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adding an AoH to an AoH
by Fletch (Bishop) on Jan 21, 2008 at 04:39 UTC | |
|
Re^2: Adding an AoH to an AoH
by bradcathey (Prior) on Jan 21, 2008 at 12:58 UTC | |
by ikegami (Patriarch) on Jan 21, 2008 at 17:44 UTC |