develooper Front page | perl.perl5.porters | Postings from March 2013

Re: Infinite loop in for (@a) { push @a, $_ }

Thread Previous | Thread Next
From:
Zefram
Date:
March 19, 2013 17:04
Subject:
Re: Infinite loop in for (@a) { push @a, $_ }
Message ID:
20130319170407.GT20429@lake.fysh.org
Brad Gilbert wrote:
>I think I would be fine with that, as long as it's optional.

Being optional would miss the point.

>I assume it would only warn/die if the length of the array can
>change.

It would die if the sequence of element identities changes.  Changing the
*values* of elements is permitted, whether through the loop's element
alias or otherwise.

>Though this is really only a problem when the length of the
>array can get bigger.

Getting shorter could be quite a problem if it means you're now on
the seventh element of three.  Any change to the array's value (the
sequence of element identities) is a problem if the iterator made the
mostly-reasonable assumption that there would be no such change.

-zefram

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About