develooper Front page | perl.perl5.porters | Postings from September 2016

[perl #129757] for loop doesn't update correct variable

Thread Previous
From:
Father Chrysostomos via RT
Date:
September 29, 2016 04:41
Subject:
[perl #129757] for loop doesn't update correct variable
Message ID:
rt-4.0.24-9483-1475124084-359.129757-15-0@perl.org
On Wed Sep 28 21:01:34 2016, aristotle wrote:
> * Mark-Jason Dominus <perlbug-followup@perl.org> [2016-09-29 03:00]:
> > Also, when correcting that bug, please make sure this is also
> > corrected:
> >
> > for my $i (1..3) {
> >   sub announce { printf "Count %d\n", $i }
> >   announce();
> > }
> >
> > It shows the same wrong behavior.
> 
> That sub is compiled just once despite its placement inside the loop
> and
> it binds $i at compile time.

This is similar to the problem that plagues lexical aliasing.  The notes I added in 514e62e37b8 may also be relevant to package subs, but I do not have time to think it through now, or in the foreseeable future.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=129757

Thread Previous


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