in reply to Perl Array of Hashes

Is it necessary to create "BUCK_1", "BUCK_2", etc? That seems like an array.

Does "BUCK" ever become something else? What if the datastructure looked more like this:

$xentry[0] = { BUCK => [ qw/JUNK JUNK JUNK JUNK/ ], TUBS => [ qw/THUMP THUMP THUMP THUMP/ ] };

Then instead of $xentry[0]->{BUCK_1} it would be $xentry[0]->{BUCK}[1], for example. I believe that not trying to create in-fix indexes in a hash key, and instead, letting arrays do your work will prove to be less headaches in the longrun.


Dave

Replies are listed 'Best First'.
Re^2: Perl Array of Hashes
by abhay180 (Sexton) on Jul 27, 2009 at 06:02 UTC
    David, Thanks for ur suggestion. I wanted to make number of "BUCK_*" as programmable. With every run of prog i want to have either "4/8/16/.." BUCKs in each entry. In a nut shell i am trying to mimic one kind of hash-table implementation,with bucket,entries e.t.c . I need the number of entries and buckets to be configurable from command line. Hence this approach i guess. Any better way of doing it would help. Thanks Abhay