in reply to building an HoAoH ... very badly
This should give youmy $appearances = []; while ( my $ref = $sth->fetchrow_hashref() ) { my $season = $ref->{season}; unless ( exists $appearances->[$season -1 ] ) { $appearances->[$season -1 ] = { season => $season, eps => [] }; } my $eps = $appearances->[$season -1 ]->{eps}; push @$eps, $ref; }
Disclaimer: untested$appearances = [ {season => 1, eps => [ {season => 1, ep => 1, title => 'Hellmouth' }, ......
Update: Note that since this code recycles the hashref from DBI, if you add more fields in your SQL later, they will show up in the final data structure as well.
|
|---|