develooper Front page | perl.perl5.porters | Postings from July 2019

[perl #134303] Using "my" in "until" statement modifier resettinglexicals from outer scope

From:
Tony Cook via RT
Date:
July 31, 2019 04:46
Subject:
[perl #134303] Using "my" in "until" statement modifier resettinglexicals from outer scope
Message ID:
rt-4.0.24-672-1564548366-970.134303-15-0@perl.org
On Tue, 23 Jul 2019 08:00:01 -0700, choroba@matfyz.cz wrote:
> As stated in the Subject: using "my" in the "until" statement modifier
> resets
> the lexical of the same name from outer scope.
> 
> See also https://www.perlmonks.org/?node_id=11103184 and especially
> the reply https://www.perlmonks.org/?node_id=11103204 for more
> details.
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> warn $];
> 
> our $our = 1;
> warn 'never' until $our = 6;
> warn "<< $our >>";                   # 6
> 
> my $mine = 1;
> warn 'never' until $mine = 6;
> warn "<< $mine >>";                  # 6
> 
> our $nil = 1;
> warn 'never' until my $nil = 6;      # my !
> warn "<< $nil >>";                   # undef
> 
> my $null = 1;
> warn 'never' until my $null = 6;     # my !
> warn "<< $null >>";                  # undef
> 
> When using "if" instead of "until", the output is always "6".
> 
> Thanks to LanX who is normally to busy/lazy to report perlbugs

newLOOPOP() calls op_scope() to wrap the statement in an enter/leave pair, and since padsv does a save_clearsv() for the my variable, it's cleared by the leave.

Tony

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



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