Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
and at some point in My::Module, I have to iterate through them:$x = My::Module->new(){ foo => 'bar', baz => qw( bax bof ) }
this works on one server ("v5.8.4 built for i386-linux-thread-multi") but not on another ("v5.8.8 built for i686-linux"). I get the error "Can't use string ("bax") as an ARRAY ref while "strict refs" in use".foreach ( @{ $self->{'baz'} } ) { # some code }
It appears that the qw isn't automagically making an anonymous array? That somehow only the first item is making it in, as a scalar?
I figured out that it'll be just fine if I change
to$x = My::Module->new(){ foo => 'bar', baz => qw( bax bof ) }
but what's going on?$x = My::Module->new(){ foo => 'bar', baz => [ 'bax' , 'bof'] }
($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Anonymous array with qw() doesn't always work?
by Joost (Canon) on Jun 13, 2007 at 13:25 UTC | |
by derby (Abbot) on Jun 13, 2007 at 14:37 UTC | |
by Joost (Canon) on Jun 13, 2007 at 14:57 UTC |