But the warning message doesn't tell me enough to go quickly to the input record that caused the problem. This is demonstrated below.
What I would like to do is: if a warning happens within compareLT105(), is to print something specific to this particular subroutine call, like: $arrayRef->[0] in addition to the Perl generated warning. That would narrow the field from ~1 million records to one record.
I don't want to "die", I just want to add something to the warning message. I read about installing a __WARN__ signal handler, but that appears to require exposing $arrayRef to a wider scope. Block eval{} works with "die".
This is of course a very simplistic version of the "real thing", but I hope provides enough info to get me on the right track.
I hope the solution is so easy that it is a "Duh!".
#!/usr/bin/perl -w use strict; $|=1; #turns off buffering for STDOUT my @x = ( [1,'100'], [2,'106'], [3,'100A'], [4,'100B2'], ); foreach my $ref (@x) { print "For $ref->[1] compareLT105 says: ", compareLT105($ref),"\n"; } sub compareLT105 { my $arrayRef = shift; return 'true' if $arrayRef->[1] < 105; return 'false'; } __END__ For 100 compareLT105 says: true For 106 compareLT105 says: false Argument "100A" isn't numeric in numeric lt (<) at C:\TEMP\warnexample +.pl line 21. For 100A compareLT105 says: true Argument "100B2" isn't numeric in numeric lt (<) at C:\TEMP\warnexampl +e.pl line 21. For 100B2 compareLT105 says: true
In reply to How to modify a warning message within a sub? by Marshall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |