develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24342] Coredump when shortening an array during use

October 29, 2003 08:13
Re: [perl #24342] Coredump when shortening an array during use
Message ID:
> > > Could someone explain why this is allowed at all ?
> > > Why can I apply -= to an array slice but not to an array ?
> >
> > Hm, probably for compatibility with the (mistaken) use
> > of a one-element slice as an array element.
> >
> > @x[2] -= 3;
> Surely its just the normal 'last element returned' behaviour of a list in
> scalar context, eg

Its not 'returned', its 'propagated'. It seems a list will return an alias
to the last element. It further seems the element is not REFCOUNT++ed (same
as with @_) and that this alias is retrieved before the right hand side of
the expression is evaluated.

So it's clear:

1.) find LVALUE fro left hand side
1.1) evaluate array slice
1.2) create $F[0] to $F[7] on first access
1.3) return alias to $F[7] from list
2.) evaluate RVALUE from right hand side
2.1) fill array with new value 3
2.2.1) set $F[0] to 3
2.2.2) DESTROY $F[1] to $F[$#F]
3.) assign 3 via alias to destroyed SV
3.1) coredump

Michael Jacob Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About