in reply to Re^3: use warnings and debug messages
in thread use warnings and debug messages
but actually this gave me an idea to use __WARN__ and caller() to check if the warning happened on a line with a debug call and hide those.use warnings; no warnings "uninitialized";
Though this will have a runtime impact we need to consider. Of course then we could cache the filename/rownumber pairs to reduce the cost. Thank you for the suggestion.use 5.010; use strict; use warnings; my $x = 42; my $y; $SIG{__WARN__} = sub { my $warn = shift; my ($package, $filename, $line) = caller; if (open my $fh, '<', $filename) { my @lines = <$fh>; return if $lines[$line-1] =~ /debug\(/; } print $warn; }; my $z = $x+$y; debug("x=$x y=$y"); sub debug { say shift; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: use warnings and debug messages ( caller(expr) )
by LanX (Saint) on Mar 08, 2017 at 01:50 UTC | |
Re^5: use warnings and debug messages
by stevieb (Canon) on Mar 08, 2017 at 00:52 UTC |