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

Re: [FWP] awww, no fun :(



On Thu, Apr 12, 2001 at 01:34:35PM -0700, Randal L. Schwartz wrote:
> 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:

I presume its supposed to be 'last_OUTER_if_init' in both places below?
Please, no more magic.

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


The more examples I see of this, the more frightened I am of it.  It
might have made sense back then, but it would terrify me to see this
used in any program of any significant size.  I'd also be a bit
worried about such stack smashing coupled with the twitchyness of
perl's signals.

A much less odd implementation...

{
  my $Caught_SIGINT = 0;
  local $SIG{INT} = sub { $Caught_SIGINT = 1 };

  while(...) {
    ...
    last if $Caught_SIGINT;
    ...
  }
}

At least that all loop conditionals are inside the loop.


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
An ice cream has its unique frequency....Are you hungry for this ice cream? Or
not? If you are, a certain part of your body is requesting to attract chemicals
from this ice cream. If you don't have the appetite, your body doesn't need any
chemical from the ice cream. Your brain is most conductive and serves as the
middleman.
	     --Alex Chiu, Immortality Guy

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