.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Perl::Critic::Policy::ValuesAndExpressions::ProhibitUnknownBackslash 3pm" .TH Perl::Critic::Policy::ValuesAndExpressions::ProhibitUnknownBackslash 3pm "2021-02-28" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Perl::Critic::Policy::ValuesAndExpressions::ProhibitUnknownBackslash \- don't use undefined backslash forms .SH "DESCRIPTION" .IX Header "DESCRIPTION" This policy is part of the \f(CW\*(C`Perl::Critic::Pulp\*(C'\fR add-on. It checks for unknown backslash escapes like .PP .Vb 1 \& print "\e*.c"; # bad .Ve .PP This is harmless, assuming the intention is a literal \*(L"*\*(R" (which it gives), but unnecessary, and on that basis this policy is under the \f(CW\*(C`cosmetic\*(C'\fR theme (see \*(L"\s-1POLICY THEMES\*(R"\s0 in Perl::Critic). Sometimes it can be a misunderstanding or a typo though, for instance a backslashed newline is a newline, but perhaps you thought it meant a continuation. .PP .Vb 2 \& print "this\e # bad \& is a newline"; .Ve .PP Perl already warns about unknown escaped alphanumerics like \f(CW\*(C`\ev\*(C'\fR under \&\f(CW\*(C`perl \-w\*(C'\fR or \f(CW\*(C`use warnings\*(C'\fR (see \*(L"Unrecognized escape \e%c passed through\*(R" in perldiag). .PP .Vb 1 \& print "\ev"; # bad, and provokes Perl warning .Ve .PP This policy extends to report on any unknown escape, with options below to vary the strictness and to check single-quote strings too if desired. .SS "Control Characters \ec" .IX Subsection "Control Characters c" Control characters \f(CW\*(C`\ecX\*(C'\fR are checked and only the conventional A\-Z a\-z @ [ \&\e ] ^ _ ? are considered known. .PP .Vb 1 \& print "\ec*"; # bad .Ve .PP Perl accepts any \f(CW\*(C`\ec\*(C'\fR and does an upcase xor 0x40, so \f(CW\*(C`\ec*\*(C'\fR is letter \*(L"j\*(R", at least on an \s-1ASCII\s0 system. But that's obscure and likely to be a typo or error. .PP For reference, \f(CW\*(C`\ec\e\*(C'\fR is the \s-1ASCII FS\s0 \*(L"file separator\*(R" and the second backslash is not an escape, except for a closing quote character, which it does escape (basically because Perl scans for a closing quote before considering interpolations). Thus, .PP .Vb 3 \& print " \ec\e "; # ok, control\-\e FS \& print " \ec\e" "; # bad, control\-" is unknown \& print qq[ \ec\e] ]; # ok, control\-] GS .Ve .SS "Ending Interpolation" .IX Subsection "Ending Interpolation" A backslashed colon, bracket, brace or dash is allowed after an interpolated variable or element, since this stops interpolation at that point. .PP .Vb 2 \& print "$foo\e::bar"; # ok, $foo \& print "@foo\e::"; # ok, @foo \& \& print "$foo[0]\e[1]"; # ok, is $foo[0] \& print "$esc\e[1m"; # ok \& \& print "$foo\e{k}"; # ok \& print "$foo\e{k}"; # ok \& print "$foo{k}\e[0]"; # ok, is $foo{k} \& print "@foo\e{1,2}"; # ok, is @foo \& \& print "$foo\e\->[0]"; # ok, is $foo \& print "$foo\e\->{zz}"; # ok .Ve .PP A single backslash like \f(CW"\e::"\fR is enough for the colon case, but backslashing the second too as \f(CW"\e:\e:"\fR is quite common and is allowed. .PP .Vb 1 \& print "$#foo\e:\e:bar"; # ok .Ve .PP Only an array or hash \f(CW\*(C`\->[]\*(C'\fR or \f(CW\*(C`\->{}\*(C'\fR need \f(CW\*(C`\e\-\*(C'\fR to stop interpolation. Other cases such as an apparent method call or arrowed coderef call don't interpolate and the backslash is treated as unknown since unnecessary. .PP .Vb 2 \& print "$coderef\e\->(123)"; # bad, unnecessary \& print "Usage: $class\e\->foo()"; # bad, unnecessary .Ve .PP For reference, the alternative in all the above is to write \f(CW\*(C`{}\*(C'\fR braces around the variable or element to delimit from anything following. Doing so may be clearer than backslashing, .PP .Vb 4 \& print "${foo}::bar"; # alternatives \& print "@{foo}::bar"; \& print "$#{foo}th"; \& print "${foo[0]}[1]"; # array element $foo[0] .Ve .PP The full horror story of backslashing interpolations can be found in \&\*(L"Gory details of parsing quoted constructs\*(R" in perlop. .SS "Octal Wide Chars" .IX Subsection "Octal Wide Chars" Octal escapes \f(CW\*(C`\e400\*(C'\fR to \f(CW\*(C`\e777\*(C'\fR for wide chars 256 to 511 are new in Perl 5.6. They're considered unknown in 5.005 and earlier (where they end up chopped to 8\-bits 0 to 255). Currently if there's no \f(CW\*(C`use\*(C'\fR etc Perl version then it's presumed a high octal is intentional and is allowed. .PP .Vb 1 \& print "\e400"; # ok \& \& use 5.006; \& print "\e777"; # ok \& \& use 5.005; \& print "\e777"; # bad in 5.005 and earlier .Ve .SS "Named Chars" .IX Subsection "Named Chars" Named chars \f(CW\*(C`\eN{SOME THING}\*(C'\fR are added by charnames, new in Perl 5.6. In Perl 5.16 up, that module is automatically loaded when \f(CW\*(C`\eN\*(C'\fR is used. \&\f(CW\*(C`\eN\*(C'\fR is considered known when \f(CW\*(C`use 5.016\*(C'\fR or higher, .PP .Vb 2 \& use 5.016; \& print "\eN{EQUALS SIGN}"; # ok with 5.16 automatic charnames .Ve .PP or if \f(CW\*(C`use charnames\*(C'\fR is in the lexical scope, .PP .Vb 4 \& { use charnames \*(Aq:full\*(Aq; \& print "\eN{APOSTROPHE}"; # ok \& } \& print "\eN{COLON}"; # bad, no charnames in lexical scope .Ve .PP In Perl 5.6 through 5.14, a \f(CW\*(C`\eN\*(C'\fR without \f(CW\*(C`charnames\*(C'\fR is a compile error so would be seen in those versions immediately anyway. There's no check of the character name appearing in the \f(CW\*(C`\eN\*(C'\fR. \f(CW\*(C`charnames\*(C'\fR gives an error for unknown names. .PP The \f(CW\*(C`charnames\*(C'\fR option (\*(L"\s-1CONFIGURATION\*(R"\s0 below) can be allow to always allow named characters. This can be used for instance if you always have Perl 5.16 up but without declaring that in a \f(CW\*(C`use\*(C'\fR statement. .PP The \f(CW\*(C`charnames\*(C'\fR option can be disallow to always disallow named characters. This is a blanket prohibition rather than an UnknownBackslash as such, but matches the allow option. Disallowing can be matter of personal preference or perhaps aim to save a little memory or startup time. .SS "Other Notes" .IX Subsection "Other Notes" In the violation messages, a non-ascii or non-graphical escaped char is shown as hex like \f(CW\*(C`\e{0x263A}\*(C'\fR, to ensure the message is printable and unambiguous. .PP Interpolated \f(CW$foo\fR or \f(CW\*(C`@{expr}\*(C'\fR variables and expressions are parsed like Perl does, so backslashes for refs within are ok, in particular tricks like \&\f(CW\*(C`${\escalar ...}\*(C'\fR are fine (see \*(L"How do I expand function calls in a string?\*(R" in perlfaq4). .PP .Vb 1 \& print "this ${\e(some()+thing())}"; # ok .Ve .SS "Disabling" .IX Subsection "Disabling" As always, if you're not interested in any of this then you can disable \&\f(CW\*(C`ProhibitUnknownBackslash\*(C'\fR from your \fI.perlcriticrc\fR in the usual way (see \&\*(L"\s-1CONFIGURATION\*(R"\s0 in Perl::Critic), .PP .Vb 1 \& [\-ValuesAndExpressions::ProhibitUnknownBackslash] .Ve .SH "CONFIGURATION" .IX Header "CONFIGURATION" .ie n .IP """double"" (string, default ""all"")" 4 .el .IP "\f(CWdouble\fR (string, default ``all'')" 4 .IX Item "double (string, default all)" .PD 0 .ie n .IP """heredoc"" (string, default ""all"")" 4 .el .IP "\f(CWheredoc\fR (string, default ``all'')" 4 .IX Item "heredoc (string, default all)" .PD \&\f(CW\*(C`double\*(C'\fR applies to double-quote strings \f(CW""\fR, \f(CW\*(C`qq{}\*(C'\fR, \f(CW\*(C`qx{}\*(C'\fR, etc. \&\f(CW\*(C`heredoc\*(C'\fR applies to interpolated here-documents \f(CW\*(C`<.