in reply to Re^2: Eval not working
in thread Eval not working

$dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; my $id = 737; my $rows; if (!eval { my $sql = "UPDATE stockhistory SET invoiced = 1 WHERE id = ?"; my $sth = $dbh->prepare($sql); $rows = $sth->execute($id); $dbh->commit(); 1 }) { print "Transaction aborted because $@"; $dbh->rollback(); } die("Record $id not found") if $rows < 1;

Note: Can't check if $rows is true since "0E0" (equal to zero but true) is returned when no rows are affected.

Replies are listed 'Best First'.
Re^4: Eval not working
by DooDah (Novice) on Sep 03, 2010 at 20:07 UTC
    Thanks for all your help monks.
    I'll re-write my script to include your suggestions.