splain command examples

splain command examples

diagnostics, splain – produce verbose warning diagnostics

The following file is certain to trigger a few errors at both runtime and compiletime:

use diagnostics;
print NOWHERE "nothing\n";
print STDERR "\n\tThis message should be unadorned.\n";
warn "\tThis is a user warning";
print "\nDIAGNOSTIC TESTER: Please enter a here: ";
my $a, $b = scalar ;
print "\n";
print $x/$y;

If you prefer to run your program first and look at its problem afterwards, do this:

perl -w test.pl 2>test.out
./splain /dev/tty) >& test.out
./splain &1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&-

If you want to control warnings on the fly, do something like this. Make sure you do the “use” first, or you won’t be able to get at the enable() or disable() methods.

use diagnostics; # checks entire compilation phase

print “\ntime for 1st bogus diags: SQUAWKINGS\n”;
print BOGUS1 ‘nada’;
print “done with 1st bogus\n”;

disable diagnostics; # only turns off runtime warnings

print "\ntime for 2nd bogus: (squelched)\n";
print BOGUS2 'nada';
print "done with 2nd bogus\n";

enable diagnostics; # turns back on runtime warnings

print "\ntime for 3rd bogus: SQUAWKINGS\n";
print BOGUS3 'nada';
print "done with 3rd bogus\n";

disable diagnostics;

print "\ntime for 4th bogus: (squelched)\n";
print BOGUS4 'nada';
print "done with 4th bogus\n";

Leave a Reply

Your email address will not be published. Required fields are marked *