http://qs321.pair.com?node_id=856292

saintex has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I have a problem, when I try to use a refernce to an hash in a subroutine.

That works:
sub test { my %q=@_; while ( my ($key, $value) = each(%q) ){ } }

But I need to modify the orginal values, not a copy through "my" .
But that:

sub test { while ( my ($key, $value) = each( {@_} ) ){ #or { $_[0] } with the +same result } }
doesn't work, because I have:
Type of arg 1 to each must be hash (not anonymous hash ({})) near "} +)

Any suggestion about I can solve that?
Thank you!

_____________ UPDATE:

On a suggestion below I write all my code:

I would like to creare a Simply SQL wrapper.
So:
my $dbh; my (%q,@select,@insert,@update,@delete); %q= ( select => \@select, insert =>\@insert, update =>\@update, delete=>\@delete ); $select[0]=['SELECT * FROM emails WHERE `email`=?']; $select[1]=['SELECT * FROM emails AS e RIGHT JOIN bounces AS b ON e.` +emails_id`=b.`emails_id` WHERE e.`email`=? AND b.`email_date`=FROM_UN +IXTIME(?) '];
And then:
sub elabora_st { # argument list: # action='prepare' or action='finish' # then the hash delle query my $action=shift @_; my %q=@_; for my $value (values %q ){ for my $sel ( @$value ) { # print "$sel->[0]\n"; if ( $action eq 'prepare') { # print "$sel->[0] \n"; my $sth=$dbh->prepare($sel->[0]); $sel->[1]=$sth; } elsif ($action eq 'finish') { # to do } } } }
Finally:
&connection; &elabora_st ('prepare',%q); # other stuff # I would like to have queries like that, or something similar: # %q->select[1][1]->execute($address,$mailTime); &end_connection;

But I need to modify the original %q, not a copy...
I think that in object orientend code, I will have a better result, but I'm not yet able to create OO Perl code.
Finally I don't want to modify the global %q, but only the %q passed through argument list.