in reply to Anonymous array with qw() doesn't always work?

qw() does not return an array, it returns a list:
$x = { foo => 'bar', baz => qw( bax bof ) }
is equivalent to
$x = { foo => 'bar', baz => 'bax', 'bof' }
And that should give you a "odd number of elements" warning if you have warnings enabled.

You can do

$x = { foo => 'bar', baz => [ qw( bax bof ) ] }
to transform the list into an anonymous array and all will be fine.

Update: removed nonsense new() calls.

Replies are listed 'Best First'.
Re^2: Anonymous array with qw() doesn't always work?
by derby (Abbot) on Jun 13, 2007 at 14:37 UTC

    What's with all the new(){ ... } constructs? Unless I'm missing something, that's a syntax error.

    -derby