[Pdx-pm] Hash question

Bruce J Keeler bruce at gridpoint.com
Fri Nov 21 22:11:35 CST 2003

On Fri, 2003-11-21 at 14:23, Roderick A. Anderson wrote:

> First the append hash solution.  I use the hash generated from some CGI.pm
> params then query a SQL Server database and and use DataHash to returned
> the row.  To append to the original hash I'm using a variation on code I
> got out of "Perl Cookbook".
> 	%SignUpInfo = (%SignUpInfo, $db2->DataHash());
> Is there a better or more efficient way to do this?

This will recreate the hash, re-adding all the elements that were there
before.  In cases where there are a lot of items in the hash to begin
with, that's going to be inefficient.  Something like this might be
better in that case:

        %tmp = $db2->DataHash();
        @SignUpInfo{keys %tmp} = values %tmp;
Though now the new hash entries are going to be hashed twice instead, so
that's less efficient in the case where there's more data being added
than was there to begin with.

More information about the Pdx-pm-list mailing list