in reply to Re: normalizing results from a db query
in thread normalizing results from a db query

I have a better understanding of your problem now, here's the code for my solution to problem #2. It's a bit hackish, but I thought I'd throw it out as one way to do it:
#!/usr/bin/perl -w use strict; use Data::Dumper; my $seen = 0; my @carmakers; while (<DATA>) { chop; my ($id, $maker, $make) = split(",", $_); if ($id != $seen) { package block1; my %maker; $maker{'thismaker'} = $maker; my @makes; my %make = ('thismake' => $make); push(@makes, \%make); $maker{'makes'} = \@makes; push(@carmakers, \%maker); # problem1 $seen = $id; } else { package block2; my %make = ('thismake' => $make); push(@block1::makes, \%make); # problem2 $block1::maker{'makes'} = \@block1::makes; } } print Dumper( @carmakers ); __DATA__ 1,gm,saturn 1,gm,chevy 1,gm,caddy 2,ford,taurus 2,ford,escort 3,vw,bug 3,vw,jetta 3,vw,phaeton
I'll think some more about problem 1, this is fun. :) Have you thought about a different way of structuring your database quer(y|ies)? For example, maybe you could use the database to get a unique set of carmakers.