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

Re: [perl #119797] lvalue sub shows "Bizarre copy of ARRAY in blockexit" in very specific case.

Thread Previous | Thread Next
From:
Zefram
Date:
October 24, 2013 11:15
Subject:
Re: [perl #119797] lvalue sub shows "Bizarre copy of ARRAY in blockexit" in very specific case.
Message ID:
20131024111509.GU21945@fysh.org
Konrad Borowski wrote:
>I checked. For some reason, subroutine or `do` block ending with `while` block 
>or `for` block always returns empty string

The standard false value is an empty string.  The last thing evaluated
by a while statement is the condition that comes up false to cause
termination of the loop.  The return value is normally the actual
false value used:

$ perl -lwe 'print do { while($_) {} } // "undef" for 0, undef'
0
undef

but it wasn't always thus when constant folding got involved:

$ perl5.16.3 -lwe 'print do { while(0) {} } // "undef"' 
undef
$ perl5.18.1 -lwe 'print do { while(0) {} } // "undef"' 
0

-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