in reply to How to determine current line executing in Script

Make use of warn, $SIG{__WARN__} and END {...}. If the argument to warn doesn't end with a new line ( warn $x." "; ) then the line number will be appended. In $SIG{__WARN__} do a "push(@log,"@_");". In the END block print @log. You probably should add a $SIG{__DIE__} where you also do the "push(@log ..." before you re-raise the die. That way you'll get a log if you "die".
  • Comment on Re: How to determine current line executing in Script

Replies are listed 'Best First'.
Re^2: How to determine current line executing in Script
by Anonymous Monk on Dec 04, 2008 at 14:08 UTC
    #!/usr/bin/perl use strict; use warnings; my @log="\n"; BEGIN { $SIG{__WARN__}=sub { push(@log,"@_"); }; $SIG{__DIE__}=sub { push(@log,"@_"); }; } # BEGIN END { if (@log) { print @log; }; } # END warn "a warning "; my $warning="just another warning\n"; warn $warning." "; die "death by request";