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
    This is pretty much what I've been looking for...

    Something seemed redundant, and I assumed it to be %departments, but you're right; @classes is not really needed.

    And ++ on the sort. I forgot to sort my keys, since it showed up fine when I was testing, but that was due too a not large enough dataset :-)

    Thanks.

    Not that it means anything of course, since any improvement I get here means a speed increase of thousandths of a second (guessing), but I was curious....

    [ar0n]