Jay Savage wrote:
Wrap the call in an eval block. Then check $@ to see if there was a
fatal error, which you can ignore if you want to or do something along
the lines of:
eval {
my $sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");
};
if ($@) {
print "Table $table -- (probably) DOES NOT EXIST\n";
next;
}
Because $@ is a global, it is best practice to act on
the return value of eval itself:
my $sth;
eval {
$sth = $dbh->prepare("SELECT COUNT(*) FROM mytable");
1; # success
}
or do {
my $eval_error = $@ || "unknown";
print $eval_error, "\n";
print "Table $table -- (probably) DOES NOT EXIST\n";
next;
};
But it is still much better to just ask for the table names,
like with "SHOW TABLES LIKE '...'", or with something like
SELECT
table_name AS _tbl
FROM
information_schema.tables
WHERE
table_schema = "db"
AND
table_name REGEXP "^abc_"
;
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/