I have the following code in in a Perl script I'm writing:
#!/usr/bin/perl
use DBI;
use Getopt::Long;
use Time::HiRes;
use Error qw(:try);
....
my $starttime = Time::HiRes::time;
try {
my $dbh = DBI->connect("dbi:Sybase:$server", $username, $password);
$dbh->do("use $database");
my $query="exec OfflineDatabaseReport";
$row = $dbh->selectrow_hashref($query);
$dbh->disconnect();
} catch Error with {
print "boom";
exit 1;
};
my $endtime = Time::HiRes::time;
my $timetaken = $endtime - $starttime;
The script worked fine until I wrapped the data access portion in the try...catch block. Now I get the following exception thrown:
Can't use string ("1316135985.90893") as a HASH ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.8/Error.pm line 217.
I did try setting:
no strict "refs";
But I still get the same error. Am I being naive in my usage of a try/catch block here?
catch {...}block -- that will come back to bite you in the you-know-where. - mob