Thanks for the reply, but that doesn't answer my question. As I thought I was careful to explain, I know the error location, but I need to determine the name of the file handle associated with the value in $.. And as a library that doesn't do file IO, I have no clue what the file might be.
There's got to be a better way than:
my $msg = " at yourbadscript line your mistake";
if( defined $. ) {
local $@ = '';
eval {
die;
};
if($@ =~ /^Died at .*(, <.*?> line \d+).$/ ) {
$msg .= $1;
}
}
$msg .= ".\n";
die $msg;
This communication may not represent my employer's views,
if any, on the matters discussed.
| [reply] [d/l] |
And as a library that doesn't do file IO, I have no clue what the file might be.
How do you know anything did IO then?
When you can answer that question, you know the right place to handle the file/line information.
| [reply] |
We aren't communicating. I'm in a library that has nothing to do with IO. I need to die gracefully and provide maximum help to my user. I don't know a priori about any IO done by my caller or her other libraries - but if $. is defined, someone, somewhere read or wrote a file. In that case, I want to provide the same information that die normally does, replacing die's call location with one more meaningful to the user. Users appreciate knowing that their problem manifested at record 5,916 of the file they know as <FROBULATOR> (or whatever).
The code snippet that I provided above gets the answer.
But it's a horrible way to get the answer. It requires an extra trapped exception, and parsing a text error message. The former is expensive, and the latter is not generally considered good practice for any number of reasons. So, If someone knows the answer to my question - how does one reliably and efficiently get the name of the file handle associated with $. - I'd appreciate an answer. Clearly, die figures it out - so it's available somewhere.
This communication may not represent my employer's views,
if any, on the matters discussed.
| [reply] |