Hello,
This doesn't directly relate to mod_perl, but I'd like to make this as
memory efficient as possible since it runs under mod_perl. :-)
I have a question about data structures. Currently, I am doing SQL
queries and returning an array ref and a hash ref. The array is to
preserve order, and the hash contains various bits of data about that
particular product ( it could be another hash ref, and often is). After
getting the two references, I use foreach to loop through the array, and
within that loop I access various data from the hash where the productID
is the key. It looks like this:
Common.pm:
sub getdata {
my $AR = [123, 456, 243, ... ]
my $HR = { 123 => {foo=>bar, name=>'name', price=>'123'}, ... }
return ($AR, $HR);
}
Otherstuff.pm:
my ($AR, $HR) = $self->getdata();
foreach (@{$AR}) {
my $name = $HR->{$_}{name};
...
}
I would like to return a single data structure, but order IS important
(hence the current setup). I was thinking of using an array, where each
element is a hash reference. So I would return something like this:
[ {ID=>123, name=>'name123', foor=>'bar'}, {ID=>321, name=>'name321',
bar=>'foo'}, ... ]
Are there any de-referenceing issues (performance wise) that would make
this less efficient than the 2 structures? TIA for any pointers.
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/