in reply to (Complex)Data Manipulation

I think what you are looking for is a AOHOH, but my preference would be to let the database (SQL) do the aggregation and grouping.

The AOHOH would be:

my @db; $db[$monthNumber]->{ProductName}{RegionName} = $Quantity; # Loop through Month.. for (0..11){ #Cycle through Months, assuming zero-based next unless my %prod = %{$db[$_]}; # Any data there ? print "Some MONTH $_ header here\n"; foreach (sort keys %prod){ my %region = %{$prod{$_}}; # $region{RegionName} now has the qty to be printed # Hopefully, you get the idea now... } }
Needless to say, the code above is untested..

    ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

Replies are listed 'Best First'.
Re^2: (Complex)Data Manipulation
by poqui (Deacon) on Feb 28, 2005 at 18:53 UTC
    Oracle SQL-wise its pretty easy:

    select product, sum(decode(region, 'asia', quantity,0)) as "Asia", sum( decode(region, 'australia',quantity,0)) as "Australia", sum( decode(region, 'UK',quantity,0)) as "UK", sum(quantity) as "Total Imported"
    from whateverthetablenameis
    group by product

    AKA: Pivot report.
Re^2: (Complex)Data Manipulation
by rupesh (Hermit) on Feb 28, 2005 at 10:21 UTC

    AOHOH was what I was looking for.
    Even though I'm done with the job, I'm benchmarking all the other algorithms that fellow monks have provided.
    Many Thanks (Again)!
    Cheers,
    Rupesh.