use Carp qw(carp cluck); # Print the message with the file and line number included carp("There was an error ['" . $dbh->errstr . "'] in the insert") if DEBUG && $debug; # Print the message with the stacktrace included cluck("There was an error ['" . $dbh->errstr . "'] in the insert") if DEBUG && $debug; #### perl -MCarp=verbose script.pl #### $context = sprintf '[%s:%d]', __FILE__, __LINE__; #### my $message = sprintf "There was an error ['%s'] in the insert", $dbh->errstr; # Print the message with the file and line number included print Carp::shortmess($message); # Print the message with the stacktrace included print Carp::longmess($message);