in reply to Data structure transformation
I'd be more inclined to remove the @classes array (unless it makes other things in your code more convenient) -- and push onto a departments hash to begin with. Something like:
my %departments; while( $sth->fetchrow() ) { push @{$departments{$department}}, { class => $class, department => $department, count => $count, }; } my @departments = map { { department => $_, classes => $departments{$_} } } keys %departments;
You could also sort on the keys to create the final array sorted by department if desired.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(ar0n) Re (2): Data structure transformation
by ar0n (Priest) on Apr 09, 2001 at 04:07 UTC |