[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] awww, no fun :(



On Thu, Apr 12, 2001 at 06:47:14PM +0100, Michael G Schwern wrote:
> I'm more than a little distrubed by this.  Consider...
> 
>   perl -wle 'sub foo { last; } while(1) { foo() }'
> 
> In any sane universe, that loop would never exit.  In perl's, it exits
> on the first iteration (with a warning).  
> 
> You shouldn't be able to use loop control functions (last, redo,
> etc...) outside a loop's lexical context.  Action at a distance at its
> finest.

You've always been able to do that though. It must be deliberate,
because it would be trivial to make it work the way you want it
to. (Just stop looking for a loop if you find a subroutine context.)

Even more bizarre is the way that goto uses the dynamic scope:

 main(); exit;
 xxx: print "xxx: outer scope\n"; exit;
 yyy: print "yyy: outer scope\n"; exit;

 sub foo { bar(); xxx: print "xxx: foo\n"; goto yyy; }
 sub bar { goto xxx; yyy: print "yyy: bar\n" }

 sub main {
   foo();
   exit;
   yyy: print "yyy: main\n";
 }


I'm sure this has Fun uses, but I haven't been able to come
up with anything especially compelling.

 .robin.

-- 
Satan, oscillate my metallic sonatas!

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe