in reply to Bug with qw in hash slice.

On second thought, it's hopeless. It uses simple parsing to determine if it should raise a warning. This code doesn't raise a warning:
print @array[ 2];
whereas this code does:
print @array[2];
I'd say, bugger all, use a different quoting character, or add a newline.
Whoa, update. Since when does typing <code>...</code> without any newlines write inlined code? That seems new.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Bug with qw in hash slice.
by danger (Priest) on Nov 23, 2001 at 20:55 UTC

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

Re: Bug with qw in hash slice. (inlined code)
by grinder (Bishop) on Nov 23, 2001 at 02:42 UTC

    Typing <code>...</code> has always written inline code. In any case, I've seen this behaviours for months and months, so it's not new...

    --
    g r i n d e r