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

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

Thread Previous | Thread Next
From:
Andy Lester via RT
Date:
September 29, 2016 01:32
Subject:
[perl #129757] for loop doesn't update correct variable
Message ID:
rt-4.0.24-10757-1475112722-674.129757-15-0@perl.org
# A self-contained test that shows the correct behavior and doesn't get into print/printf.

require "t/test.pl";

my $i = 2112;

ok( $i == 2112, '$i starts at 2112' );

my $n;
for $i (1..3) {
    ++$n;
    ok( $i == $n, '$i is ' . $n . ' inside of the for loop' );
    somesub();
}

ok( $i == 2112, '$i should go back to 2112 outside of the loop' );

exit 0;

sub somesub {
    ok( $i == $n, '$i is ' . $n . ' in the subroutine' );
}

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

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