Indeed. As a bit of follow-up info to japhy's post: perl will issue the slice warning whenever what's inside a slice subscript (hash or array) matches the character class: [\w \t"'$#+-] from start to finish. Thus, we get warnings when the qw() operator uses any of: " ' $ + - # as delimiters --- with the exception of when something not in the character class above is inside the qw() operator (like qw'b *'). This also means that using such characters results in no warnings given even when one should be emitted (as in japhy's example of including a newline in the subscript). Here are a few more examples with hash slices:

%h = (a => 1, b => 2, "*" => 3, 4 => '4a', ab => 42); @a = (1,2,3,4); $_ = 'aaaa'; print qq|@h{s+a+a+g}\n|; # 4a: warnings print qq|@h{s/a/a/g}\n|; # 4a: no warnings print qq|@h{qw'a b'}\n|; # 1 2: warnings print qq|@h{qw"a b"}\n|; # 1 2: warnings print qq|@h{qw+a b+}\n|; # 1 2: warnings print qq|@h{qw(a b)}\n|; # 1 2: no warnings print qq|@h{qw/a b/}\n|; # 1 2: no warnings print qq|@h{qw'b *'}\n|; # 2 3: no warnings print qq|@h{2 + 2}\n|; # 4a: warnings print qq|@h{3 + 5 - 4}\n|; # 4a: warnings print qq|@h{2 * 2}\n|; # 4a: no warnings print qq|@h{(3 + 5) - 4}\n|; # 4a: no warnings print qq|@h{'a'}\n|; # 1: warnings print qq|@h{'*'}\n|; # 3: no warnings print qq|@h{qq*a*}\n|; # 1: no warnings print qq|@h{'a'.'b'}\n|; # 42: no warnings print qq|@h{$a[3]}\n|; # 4a: no warnings print qq|@h{scalar @a}\n|; # 4a: no warnings

The simple parsing scheme used is doomed both to issue inappropriate warnings, and neglect to issue appropriate warnings. Given that this is a parse/compile time warning and there can be arbitrary expressions in the subscript, getting it right would be very difficult at best (perhaps impossible).


In reply to Re: Re: Bug with qw in hash slice. by danger
in thread Bug with qw in hash slice. by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.