bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monasterians
In preparation for a nested HTML::Template tmpl_loop I loop through the AoH results of a MySQL query attempting to add a second AoH to a key of the original AoH. (I whittled this down as much as possible)
my $stmt = 'SELECT projects FROM time_sheet WHERE subscriber_id = ?'; + my $proj = $dbh->selectall_arrayref($stmt, {Slice => {}}, $subscriber_ +id); $stmt = 'SELECT users FROM time_sheet project_id = ?'; for my $i ( 0 .. $#$proj ) { my $time = $dbh->selectall_arrayref($stmt, {Slice => {}}, $project_ +id); for my $j ( 0 .. $#$time ) { push @users, $time->[$j]; } $proj->[$i]{'users'} = \@users; undef @users; }
But a Data::Dumper produces a bizarre value for users =>
print Dumper($proj); $VAR1 = [ { 'number' => 'CGL00507', 'project_title' => 'Website', 'subtotal' => 2, 'users' => $VAR1->[0]{'users'}, 'project_id' => '7599' } ];
Strange, because when I run a separate test:
my $AoH_class = [ { 'class' => 'Algebra', 'room' => '204', }, { 'class' => 'Science', 'room' => '413', } ]; my @AoH_algebra = ( { 'name' => 'Fred', 'level' => 'junior', }, { 'name' => 'Barney', 'level' => 'senior', } ); $AoH_class->[1]{'students'} = \@AoH_algebra; print Dumper($AoH_class);
I get the desired results of:
$VAR1 = [ { 'class' => 'Algebra', 'room' => '204' }, { 'students' => [ { 'level' => 'junior', 'name' => 'Fred' }, { 'level' => 'senior', 'name' => 'Barney' } ], 'class' => 'Science', 'room' => '413' } ];
What am I missing, fellow monks? TIA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding an AoH to an AoH
by ikegami (Patriarch) on Jan 21, 2008 at 03:21 UTC | |
by Fletch (Bishop) on Jan 21, 2008 at 04:39 UTC | |
by bradcathey (Prior) on Jan 21, 2008 at 12:58 UTC | |
by ikegami (Patriarch) on Jan 21, 2008 at 17:44 UTC |