Depending on the layout of your code the line number sometimes isn't enough and you start printing information about who called you. Carp can also upgrade carp to cluck by running perl as follows: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 D +EBUG && $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
Alternately, you could get the current file and line number like this:
Or if you wanted to use the stack trace provided by Carp you could get that format like this:$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);
In reply to Re: Determining a line number the error occurs on
by imp
in thread Determining a line number the error occurs on
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |