Marshall has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to modify a warning message within a sub?
by shmem (Chancellor) on Aug 09, 2011 at 02:45 UTC | |
by Marshall (Canon) on Aug 09, 2011 at 03:53 UTC | |
|
Re: How to modify a warning message within a sub?
by moritz (Cardinal) on Aug 09, 2011 at 05:01 UTC | |
by Marshall (Canon) on Aug 09, 2011 at 05:19 UTC | |
|
Re: How to modify a warning message within a sub?
by Monkomatic (Sexton) on Aug 09, 2011 at 22:33 UTC | |
|
Re: How to modify a warning message within a sub?
by Anonymous Monk on Aug 09, 2011 at 20:53 UTC |