in reply to Re: Bug with qw in hash slice.
in thread Bug with qw in hash slice.

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).