darren chamberlain writes:

> * A. Pagaltzis <pagaltzis at gmx.de> [2003-11-03 17:38]:
> 
> > * Orton, Yves <[EMAIL PROTECTED]> [2003-11-03 17:27]:
> > >
> > > > If the 'foo' attribute hasn't been set to anything, then you
> > > > want an empty list to iterate over.  With version C, that's
> > > > what you get.
> > > 
> > > No. If $self->{foo} is undef you get an error with version C.
> > 
> > You're forgetting autovivification. If $self->{foo} is undef it is
> > coerced into a appropriate reftype.
> 
>   $ perl -Mstrict -wle 'my $f = { }; my @a = @{ $f->{foo} }'
>   Can't use an undefined value as an ARRAY reference at -e line 1.

Oh, so it does there -- I didn't know that, probably because taking a
copy of an array is fairly unusual.  But it does work with foreach and
push:

  $ perl -Mstrict -wle 'my $f = { }; foreach (@{$f->{foo}}) { print };
  push @{$f->{foo}}, "hello"; foreach (@{$f->{foo}}) { print }; my @a =
  @{$f->{foo}};'

That's the kind of thing I do all the time with $self when $self is a
hash-ref, and hence the desire for attribute_list() to do something
difference when I can't use a hash-ref and am using fake, I mean ...
out-of-band, attributes instead!

Smylers

Reply via email to