On Thu Oct 07 16:16:46 2010, RJRAY wrote:
Show quoted text> The following line:
>
> my $str = '\Q' . join(q{|} => @list) . '\U';
>
> Causes two instances of
> ValuesAndExpressions::RequireInterpolationOfMetachars to be reported. It
> seems that the alternative (expressing them as "\\Q" and "\\U") is less
> clear to the reader. Should this policy only report on instances of '\c'
> when c is a legitimate special character? (\n, \t, etc.)
>
> Randy
Thank you for your report.
I sympathize, but the characters you report are, in fact, special in
Perl, though they are not in other languages. I quote from 'perldoc perlop':
The following escape sequences are available in constructs that
interpolate, but not in transliterations.
\l lowercase next char
\u uppercase next char
\L lowercase till \E
\U uppercase till \E
\E end case modification
\Q quote nonâword characters till \E
For example,
$ perl -le 'print "\Ufoo"'
prints "FOO".
So, just as this policy flags '\n' because it looks like an attempt to
interpolate a newline, it flags '\U' because it looks like an attempt to
uppercase the rest of the string. I conclude from this that both "\Q"
and "\U" should in fact be flagged by this policy, for the same reason
that "\n" is.
But there are a couple complications.
First of all, this policy does _not_ recognize "\l" (lowercase the next
character), due to a typo (it checked for "\L" twice), nor does it
recognize the \N{...} Unicode names (which appears in 'perlop' a couple
paragraphs above the part I cut-and-pasted). As an example of the latter,
$ perl -Mcharnames=:full -le 'print "\N{LATIN SMALL LETTER F}"'
prints "f".
Second, the "\Q" case seems a bit muddled. The document just cited says
that "\Q" quotes all non-word characters until "\E". It certainly does
in regular expressions. But this means to me that
$ perl -le 'print "\Q\n"'
should print '\n' (i.e. a back slash followed by a lower-case n). In
fact, it prints a back slash followed by two line feeds (one from the
-l), with nary an "n" to be found.
So resolving "\Q" in a satisfactory manner may involve a ticket to Perl,
to find out if the bug is in the code or the documentation (or in my
reading of the docs).
Tom