Lvalue vs rvalue, and yes, this depends on which operation is being invoked. mark On Thu, Nov 06, 2003 at 05:46:56PM -0000, Orton, Yves wrote: > Hi, > > Im trying to figure out an aspect of the autovivification. Specifically why > the construct being used changes whether autovivification occurs or not. Ie > for the deref @{EXPR}, whether autovivification occurs is dependent on both > the type of EXPR and the context within which @{EXPR} is used. > > For instance > > D:\>perl -Mstrict -wle "my $f = { }; my @a=map { $_ } @{ $f->{foo} }" > > D:\>perl -Mstrict -wle "my $f = { }; print 'ok' for @{ $f->{foo} }" > > D:\>perl -Mstrict -wle "my $f = { }; my @a=@{ $f->{foo} }" > Can't use an undefined value as an ARRAY reference at -e line 1. > > D:\>perl -Mstrict -wle "my $f = { }; print 'ok' if @{ $f->{foo} }" > Can't use an undefined value as an ARRAY reference at -e line 1. > > D:\>perl -Mstrict -wle "my $f = { }; print 'ok' for @{ undef() }" > Can't use an undefined value as an ARRAY reference at -e line 1. > > Now im well aware that @{EXPR} autovivifies when its directly or indirectly > used as STORE, ie: > > D:\>perl -Mstrict -wle "my $f = { }; push @{ $f->{foo} },'foo'" > > But why does it autovivify in a FETCH here: > > D:\>perl -Mstrict -wle "my $f = { }; pop @{ $f->{foo} }" > > but not here > > D:\>perl -Mstrict -wle "my $f = { }; print 'ok' if @{ $f->{foo} }" > Can't use an undefined value as an ARRAY reference at -e line 1. > > Any wisdom regarding this would be welcome. > > Yves -- mark@mielke.cc/markm@ncf.ca/markm@nortelnetworks.com __________________________ . . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder |\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ | | | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada One ring to rule them all, one ring to find them, one ring to bring them all and in the darkness bind them... http://mark.mielke.cc/Thread Previous | Thread Next