in reply to Incorrect warning when using hash slices?

I also confirmed the warning message (I'm on v5.12.2).

But, it only seems to happen with the # delimiters. If I use other delimiters, I get no warnings:

$ perl -wE '$foo{a}=1; $foo{b}=2; say join",", @foo{qw{a b}}' 1,2 $ perl -wE '$foo{a}=1; $foo{b}=2; say join",", @foo{qw/a b/}' 1,2 $ perl -wE '$foo{a}=1; $foo{b}=2; say join",", @foo{qw(a b)}' 1,2 $ perl -wE '$foo{a}=1; $foo{b}=2; say join",", @foo{qw#a b#}' Scalar value @foo{qw#a b#} better written as $foo{qw#a b#} at -e line +1. 1,2 $

Results are similar on v5.8.9 (using print instead of say).

Update: Here is a quote from qw -> Quote Like Operators:

A common mistake is to try to separate the words with comma or to put comments into a multi-line qw-string. For this reason, the use warnings pragma and the -w switch (that is, the $^W variable) produces warnings if the STRING contains the "," or the "#" character.

It is probably best to avoid # delimiters with qw.

Replies are listed 'Best First'.
Re^2: Incorrect warning when using hash slices?
by ikegami (Patriarch) on Apr 26, 2011 at 16:03 UTC

    The fact that it warns about "#" in some other context is no reason not to use it.

    Nonetheless, I'd avoid it in case someone allows qw to include comments (although that would requires a use 5.xxx;).