Re: [perl #74782] bogus warning (that gives bad advice) with qw hash slice keys
[email protected] (Tony Cook)
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Apr 29, 2010 at 01:20:13PM -0700, David Nicol wrote:
> # New Ticket Created by David Nicol
> # Please include the string: [perl #74782]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=74782 >
>
>
> Bogus warning with strawberry 5.8.9, when making a list using
> qw'...'or qw"..." (but not any other characters) Also in a freshly
> compiled
> 5.8.9. And in cygwin's 5.10.1.
>
> Whatever identifies scalar values and generates the warning is simply
> mistaken here, possibly not prepared for qw changing the meaning of
> $quot; and '.
The problem isn't qw specifically, other constructions can cause the
same warning:
perl -wce 'sub foo() { qw/abc def ghi/ } @X{+foo} = ( 1 .. 3 );'
Scalar value @X{+foo} better written as $X{+foo} at -e line 1.
Name "main::X" used only once: possible typo at -e line 1.
perl -we '$_ = "abc"; @X{split ""} = ( 1 .. 3 );'
Scalar value @X{split ""} better written as $X{split ""} at -e line 1.
And other characters can be used with qw:
perl -we '@X{qw$abc def ghi$} = ( 1 .. 3 )'
Scalar value @X{qw$abc def ghi$} better written as $X{qw$abc def ghi$} at -e line 1.
The code that produces the warning uses a fairly simple heuristic to
try and detect incorrect usage of @foo[...] or @foo{...} - it scans
for the closing ] or }, skipping alphanumeric characters and a few
others.
I don't really see a way to fix this without moving it up to checking
the generated ops.
Tony