Warnings#
Non-fatal diagnostics. A warning prints one line to STDERR and the program runs on. The severe (S) warnings print even without the warnings pragma; the plain W warnings print only when warnings are enabled for their category:
use warnings; # all categories on
no warnings 'recursion'; # silence just deep-recursion
use warnings FATAL => 'utf8'; # make utf8 warnings die instead
The category in a (W category) badge is exactly the string you pass to no warnings.
Deep recursion#
`Deep recursion on subroutine "%s"`#
(W recursion) A subroutine has called itself (directly or through a chain) more than a hundred levels deep. This is usually a runaway recursion - a base case that never fires - rather than genuinely deep work. The message names the subroutine.
use warnings;
sub countdown {
my $n = shift;
countdown($n + 1); # bug: should be $n - 1, never stops
}
countdown(1);
# Deep recursion on subroutine "main::countdown" at script line 5.
Fix the base case. If the recursion really is meant to run deep, silence the category for that scope:
no warnings 'recursion';
Wide characters#
`Wide character in %s`#
(S) A string containing a character above codepoint 255 was sent to a byte-oriented operation - most often print to a filehandle with no :encoding layer. Perl emits the bytes of the internal UTF-8 form and warns, because the output stream was never told it would carry Unicode.
use warnings;
print "café\x{2603}\n"; # Wide character in print at ... line 2.
The fix is to tell the stream its encoding:
binmode STDOUT, ':encoding(UTF-8)';
print "café\x{2603}\n"; # no warning; correct UTF-8 bytes
This is a severe (S) warning: it prints even without use warnings, because silently emitting raw internal bytes is almost always a bug.
Useless constructs#
`Useless use of \E`#
(W regexp) An \E in a pattern or string closes a \U, \L, \Q case/quote span that was never opened. The \E has nothing to end. Remove it, or add the opening \U/\L/\Q it was meant to close.
Group names#
`Invalid character in group name`#
(W) A regex named group ((?<name>...)) contains a character that is not allowed in a group name. Group names follow identifier rules - letters, digits, and underscore, not starting with a digit. The pattern still compiles, treating the construct leniently, but the name is suspect.
Encoding#
`Cannot find encoding "%s"`#
(S) A :encoding(...) layer or an Encode call named an encoding that is not available. Check the spelling against the encodings Encode supports (UTF-8, Latin-1, ASCII, and the rest).
Catch-all#
`Warning: something's wrong`#
(W) A generic warning the codegen raises for a condition that has no more specific message. The surrounding context names what triggered it.
See also#
warnings- the pragma that enables, scopes, and categorizes every W warning.$SIG{__WARN__}- intercept warnings at runtime instead of letting them reachSTDERR.Regex compilation errors - the fatal regex diagnostics, as opposed to the warning-level ones here.
Encode- the encoding names behind the “Cannot find encoding” warning.