saintex has asked for the wisdom of the Perl Monks concerning the following question:
sub test { my %q=@_; while ( my ($key, $value) = each(%q) ){ } }
doesn't work, because I have:sub test { while ( my ($key, $value) = each( {@_} ) ){ #or { $_[0] } with the +same result } }
Type of arg 1 to each must be hash (not anonymous hash ({})) near "} +)
And then: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(?) '];
Finally: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 } } } }
&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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: deferencing an hash in a subroutine
by BioLion (Curate) on Aug 20, 2010 at 15:09 UTC | |
Re: deferencing an hash in a subroutine
by moritz (Cardinal) on Aug 20, 2010 at 15:06 UTC | |
by saintex (Scribe) on Aug 20, 2010 at 15:13 UTC | |
by moritz (Cardinal) on Aug 20, 2010 at 15:19 UTC | |
by saintex (Scribe) on Aug 20, 2010 at 16:28 UTC | |
Re: deferencing an hash in a subroutine
by zentara (Cardinal) on Aug 20, 2010 at 15:06 UTC | |
Re: deferencing an hash in a subroutine
by murugu (Curate) on Aug 20, 2010 at 16:36 UTC | |
by saintex (Scribe) on Aug 20, 2010 at 17:02 UTC |