in reply to adding to a hash

How effecient would this be:
When I call the get_page_content("names"); what if I passed the current hash there, and just had the sub get_page_content intercept it, and instead of doing
my $temp_vars;
I could do:
my ($type,%temp_vars) = @_;
Then it would be pre-populated with all the current data, and add all the new data, then pass it back in the return.

Would that be a "secure" or good way of doing it?

thx,
Richard

Replies are listed 'Best First'.
Re: Re: adding to a hash
by Thelonius (Priest) on May 13, 2003 at 20:49 UTC
    That would work, but it would be more efficient to pass the hash by reference:
    get_page_content(\%variables, "names"); # instead of %variables = get_page_content("names"); sub get_page_content { my ($hashref, $type) = @_; my $dbh = DB_File::connect(); $sth = $dbh->prepare (qq{ SELECT `name`,`value` FROM `page_variabl +es` WHERE `type` = ? }); $sth->execute($type); while(my ($db_name,$db_content) = $sth->fetchrow_array()) { $$hashref{$db_name} = $db_content; } $sth->finish(); }