develooper Front page | perl.perl5.porters | Postings from January 2014

[perl #2166] foreach spuriously autovivifies

Thread Next
Father Chrysostomos via RT
January 24, 2014 02:20
[perl #2166] foreach spuriously autovivifies
Message ID:
On Mon Sep 06 05:57:18 2010, davem wrote:
> I'm marking this ticket as rejected/wontfix, because no-one can agree on
> whether for() should auto-vivify, and if there was agreement, changing
> it would break backwards compatibility.

I have just discovered this ticket, as there is a to-do test for it, which I found when about to add a test for #115194 (a duplicate).

I did not realise this was so controversial.

The problem here is that I broke compatibility (and App::JobLog) when making foreach(pos $x || pos $y) work (by propagating the lvalue context to allow $_ assignment to set pos).  Now foreach($h{k} || $h{l}) vivifies the elements, whereas it did not before.

The obvious solution seemed to be to use defelem magic in foreach, as we already do for sub calls.

Come to think of it, this has already been inconsistent, as constant folding will make for(1||$h{k}) vivify even before my changes.

So I think we need to bite the bullet and decide that this is a bug that needs fixing.


Father Chrysostomos

via perlbug:  queue: perl5 status: rejected

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