Gunther Birznieks wrote:
> 
> Using tied hashes, you could conceivably make your own ordered hash class
> and use that as the data structure you return. You'd still basically have
> two data structures (for performance) but the fact that it is two data
> structures would be hidden behind the tied hash which would be programmed
> to iterate the keys using the array rather than the keys function on the
> hash part.
> 
> I think there is source code for this publicly available, but I forget
> where I saw it. You can get some docs from perldoc perltie though.
I know about tied hashes - Thanks Damien for your excellent book! - but
there is a performance penalty. How big is this penalty? Is it worth
using tied hashes? Versus an array of hash refs?

> At 12:39 PM 6/6/00 -0400, Drew Taylor wrote:
> >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/

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/

Reply via email to