in reply to Hex to array conversion

I came across a warning I hadn't seen before when initialising an array of RGBs when looking at this.

my @rgbVals = qw{ #ff00ff #2e7fee };

warned with

Possible attempt to put comments in qw() list ...

The category I found to switch the warning off was "syntax" which potentially covers a lot of ground; "comment" or "comments" was not recognised. Here's the code

use strict; use warnings; my @rgbVals = do { no warnings q{syntax}; qw{ #ff00ff #2e7fee }; }; print map { qq{@{ [ join q{,}, map { hex } m{^.(..)(..)(..)} ] }\n} } @rgbVals;

I'd be interested in knowing if there was some finer-grained warnings category covering this.

Cheers,

JohnGG

Update: Thanks to toolic, TGI and FunkyMonk for the responses. I did try to find out in warnings but no luck there. I found "syntax" in a table in the Camel book (3rd Edn. pp 863) but didn't see "qw".

Replies are listed 'Best First'.
Re^2: Hex to array conversion
by TGI (Parson) on Oct 08, 2007 at 18:48 UTC
    The category is qw.
    use warnings; @foo = qw( #foo bar,baz ); # Throw a warning; { no warnings 'qw'; @foo = qw( #foo bar,baz ); # Don't throw a warning; }


    TGI says moo

Re^2: Hex to array conversion
by FunkyMonk (Bishop) on Oct 08, 2007 at 20:54 UTC
    diagnostics will tell you which category a warning belongs to:
    Possible attempt to put comments in qw() list at /temp/pm line 21 (#1) (W qw) qw() lists contain items separated by whitespace; as with l +iteral ...

    The last line quoted above starts (W qw) telling you that this warning belongs to the qw category.

Re^2: Hex to array conversion
by toolic (Bishop) on Oct 08, 2007 at 15:32 UTC
    That is a great question, and I wish I knew the answer.

    You could always do it the hard way:

    my @rgbVals = ('#ff00ff', '#2e7fee');
    The disadvantage of this is that you lose the capability of the qw operator. The advantage is that you do not have to turn off warnings and worry about what you might be missing.