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

Re: [FWP] awww, no fun :(



>>>>> "Jeff" == Jeff Pinyan <jeffp@crusoe.net> writes:

>> 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).  

Jeff> Except that this functionality was explicitly added to Perl, around 5.005
Jeff> I believe.

No, it's deliberately worked that way since Perl version 1 (maybe 2)
when last/next/redo were created.

That's to be able to write loop controls like:

sub last_OUTER_if_int { last OUTER; }

{ local $SIG{INT} = 'last_if_int';

  OUTER: while ($some_cond) {
    ...
    ...
    ...
    ...
  }
}

There... now we break the loop on int, rather than break the program.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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