I'm trying to run all my DBI calls through a subroutine:
sub db_execute {
my(@return,@a,$cursor);
unless($VARS{connected}){db_connect();$VARS{connected}++;}
undef @return;
$cursor = $dbh->prepare($_[0]);
$cursor->execute || db_error();
unless($_[1]){
while (@a = $cursor->fetchrow){push (@return,@a)}
return (@return);
}
}
The idea is to get it to automatically handle the errors. The connect and error subs work.
What I want to do is push to @return a reference (I think) to @a, so later I can call something along the lines of:
my $SQL = "select a,b,c from table";
my @lines = db_execute($SQL);
while( ($a,$b,$c) = @lines ){
..
}
What changes do I have to make above to get this to work?
Thanks,
madhatter