You can get a more customizable effect via %SIG handlers. A quick proof-of-concept:
use IO::Handle; my $filename = "/etc/passwd"; open my $fh, '<', $filename or die $!; my $customerr = sub { my $msg = shift; $msg =~ s/\.?\s*$//; return "$msg ($filename line ".$fh->input_line_number.")\n"; }; local $SIG{__WARN__} = sub { warn $customerr->(shift) }; local $SIG{__DIE__} = sub { die $customerr->(shift) }; while (<$fh>) { warn "BEEP!" if /root/; die "ACK!" if /nobody/; } close $fh; __END__ BEEP! at - line 12, <$fh> line 1 (/etc/passwd line 1) ACK! at - line 13, <$fh> line 7 (/etc/passwd line 7)
It may be a little more work than using Perl's built-in mechanisms, but it works great in other cases too - for example if you're going over the rows of a spreadsheet, you can include the row number in the error message.
In reply to Re: Here there be cammels!
by Anonymous Monk
in thread Here there be cammels!
by hildred
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |