sub test {
my %q=@_;
while ( my ($key, $value) = each(%q) ){
}
}
####
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 "} )
##
##
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_UNIXTIME(?) '];
##
##
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;