Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a data structure Question. I am a newbie to perl. I need to query out data from a different table and the data should looks like the below,
COLA COBB .... COLn 1 1 1 2 2 2 . . . . . . n n n


these cols are quesried out from different tables which is in an EAV type schema.
I mean I will get one whole column, COLA , then COL B,COLC etc..How I can store it in an tablular form like above and can be identified by like a COLA as primary key.
I want to edit some of these vaues in some of these queried data according to the user requests.
May I know what is the best way to do this. Is there any perl module to achive this?
what is the best data structure to hold these type of data?

Thanks,
Tom

Replies are listed 'Best First'.
Re: Data Structure Question
by GrandFather (Saint) on Nov 07, 2009 at 23:23 UTC

    Sounds like a hash of arrays might be appropriate:

    use strict; use warnings; use Data::Dump::Streamer; my @colA = ('a01' .. 'a10'); my @colB = qw(red green blue green white gray orange brown purple mauv +e); my %colHash; push @{$colHash{$colA[$_]}}, $colB[$_] for 0 .. $#colA; my @colC = (1 .. 10); push @{$colHash{$colA[$_]}}, $colC[$_] for 0 .. $#colA; Dump (\%colHash);

    Prints:

    $HASH1 = { a01 => [ 'red', 1 ], a02 => [ 'green', 2 ], a03 => [ 'blue', 3 ], a04 => [ 'green', 4 ], a05 => [ 'white', 5 ], a06 => [ 'gray', 6 ], a07 => [ 'orange', 7 ], a08 => [ 'brown', 8 ], a09 => [ 'purple', 9 ], a10 => [ 'mauve', 10 ] };

    True laziness is hard work
      Thanks much for the explanation.That will work for me.

      Tom
Re: Data Structure Question
by keszler (Priest) on Nov 07, 2009 at 23:07 UTC
    perldsc - check out hashes of arrays in particular.