Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Signal handlers, scoping & control confusion Message-ID: <11708@jpl-devvax.JPL.NASA.GOV> Date: 7 Mar 91 00:16:48 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 37 In article lgy@phys.washington.edu (Laurence G. Yaffe) writes: : (a) The 'last loop' statement inside the handler 'interrupt' does seem : to work. If I omit the statement label on the 'last' statement inside : the handler, then perl occasionally dumps core (this is at PL37). : Should a label-less 'last', 'redo', etc. statement inside a : nested subroutine work? Some think it should, and some think it shouldn't. I think that it should, but that it's bad programming style to make use of it. :-) As Tom mentioned, eval '&some_routine' is the approved method of trapping exceptions. Use "die" to raise exceptions. : Even if the subroutine is a signal handler? Next, last and redo are done via setjmp/longjmp, so if you can longjmp out of a signal handler, Perl should be able to also. : What determines if a statement label is in scope - : lexical (static) scoping or dynamic scoping? Purely dynamic. It keeps a label stack and walks up it whenever you refer to an outer label. You can even use the same label on different (non-nested) loops--Perl doesn't care, and will terminate the loop you're in rather than some other loop. : (b) Calling the 'interrupt' from within the 'compare' routine works. : Should it? Although this is very convenient for my purposes, : I would have expected 'interrupt' not to be in scope within the : 'compare' routine. You can put a subroutine declaration anywhere, and it will be visible from anywhere else within the same package. Likewise for formats. The only way to hide such declarations is with a package declaration, which is Perl's only static scoping mechanism. Larry