The structure my template needs looks like this:while ( $sth->fetchrow() ) { push @classes, { class => $class, department => $department, count => $count }; }
Now, to get to the point; I'm using the following to get what I want:@departments = ( { department => "v6" classes => [ { class => "Chemistry", department => "v6", count => 18 }, { class => "German I", department => "v6", count => 27 }, etc ... ] }, { department => "h4" classes => [ { class => "French II", department => "h4", count => 9 }, etc ... ] }, etc ... );
And it works, but.... it just rubs me the wrong way (take that Christina Aguilera!). It's icky. I don't like that temporary hash very much.my %departments; push @{ $departments{ $_->{department} }{classes} }, $_ foreach (@clas +ses); my @departments = map { $_->{department} = $_->{classes}[0]{department}; $_ } values %departments;
In reply to Data structure transformation by ar0n
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |