ar0n has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data structure transformation
by danger (Priest) on Apr 07, 2001 at 20:55 UTC | |
by ar0n (Priest) on Apr 09, 2001 at 04:07 UTC | |
|
Re: Data structure transformation
by araqnid (Beadle) on Apr 07, 2001 at 20:29 UTC | |
|
(dkubb) Re: (2) Data structure transformation
by dkubb (Deacon) on Apr 09, 2001 at 03:25 UTC |