our $dbh = DBI->connect("DBI:Oracle:$dbsid", $dbuser, $dbpassw,{'AutoCommit'=>0}); our ($dbh_start, $dbh_error); # Global flags mutate during use of the module sub start_trans() { my $proc = (caller(1))[3]; my $error; warn "Starting $proc\n"; if (not defined $dbh_start) { $dbh_start = $proc; } } sub end_trans() { my $proc = (caller(1))[3]; warn "Exiting $proc\n"; if ($dbh_start eq $proc) { if (not defined $dbh_error) { warn "Commited Transaction in $proc\n"; $dbh->commit; $dbh_error = undef; } else { warn "Rolled back Transaction in $proc\n"; warn "because $dbh_error\n"; $dbh->rollback; $dbh_error = undef; } $dbh_start = undef; } }