The use of diagnostics also sends the -w errors, so there is no need to use both in the same program.
#!/usr/local/bin/perl use diagnostics; my $a = 5; my $b = "John"; my $sum = $a + $b; #we used a string ($b) inside a numeric operation print "sum: $sum\n"; my $c = 0; my $d = 5/$c; #run-time error: illegal division by zero print "d: $d\n";
Argument "John" isn't numeric in addition (+) at ./diag.pl line 8 (#1)
(W numeric) The indicated string was fed as an argument to an operator that
expected a numeric value instead. If you're fortunate the message
will identify which operator was so unfortunate.
sum: 5
Illegal division by zero at ./diag.pl line 12 (#2)
(F) You tried to divide a number by 0. Either something was wrong in your
logic, or you need to put a conditional in to guard against meaningless input.
Uncaught exception from user code:
Illegal division by zero at ./diag.pl line 12.