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

[perl #114922] subroutine call in a loop shoudn't break it

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
September 15, 2012 13:35
Subject:
[perl #114922] subroutine call in a loop shoudn't break it
Message ID:
rt-3.6.HEAD-11172-1347741307-60.114922-15-0@perl.org
On Sat Sep 15 10:28:37 2012, s.zuban@gmail.com wrote:
> This is a bug report for perl from s.zuban@gmail.com,
> generated with the help of perlbug 1.39 running under perl 5.14.2.
> 
> # Attempt to call loop control operators like "last" out of loop
> should
> # produce an error, but the following code continues to work. The most
> dengerous thing that any subroutine called in a loop may break it!
> 
> sub test
> {
>     my $x = shift;
> 
>     if( $x > 5 )
>     {
>         last;
>     }
> }
> 
> foreach( 1..10 )
> {
>     warn $_;
>     test( $_ );
> }
> 
> # but the following call detects incorrect use of "last" and results
> in "Can't "last" outside a loop block" error
> # test( 10 );

I’d call that a feature.  There is much code that relies on it.

However, we *do* have a warning, as it is easy to use this by mistake.

If you want to make it an error, you can use:

    use warnings FATAL => 'exiting';

-- 

Father Chrysostomos


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

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