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

[perl #120954] perlsub should be more explicit when an implicit return encounters an if(){} statement

Thread Previous
From:
Tony Cook via RT
Date:
January 9, 2014 03:59
Subject:
[perl #120954] perlsub should be more explicit when an implicit return encounters an if(){} statement
Message ID:
rt-4.0.18-20269-1389239957-1217.120954-15-0@perl.org
On Wed Jan 08 09:16:36 2014, daoswald wrote:
> perlsub says this about implicit returns:
> 
>     If no return is found and if the last statement is an
>     expression, its value is returned. If the last statement is
>     a loop control structure like a foreach or a while , the
>     returned value is unspecified.
...
> Although this behavior is possibly a little confusing to
> someone who doesn't read between the lines in perlsub, it seems
> reasonably stable (it's been with us forever), and unlikely to
> change in the future.  Therefore, perlsub should state the
> following:
> 
> If no L<return> is found and if the last statement is an
> expression, its value is returned.  If the last statement
> is an C<if( CONDITION ) { BLOCK }> construct, the value
> of the return value will come from C<BLOCK> if C<CONDITION>
> is true, or from C<CONDITION> if C<CONDITION> is false.
> Relying on this behavior is detremental to code legibility.
> If the last statement is a loop control structure like a
> C<foreach> or a C<while>, the returned value is unspecified.

For reference, the current text was set in 
dbb128be9d98f2152d3ce957d4c3c518a9f86260 and 
9a9897716602799978192865b19161f65ea040c1.

It was discussed in the following threads:

http://www.nntp.perl.org/group/perl.perl5.porters/2005/10/msg105810.html

http://www.nntp.perl.org/group/perl.perl5.porters/2005/10/msg105889.html

I think the current text is fine.

Tony

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

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