Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!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: Weird response of "next" inside sub? Message-ID: <11706@jpl-devvax.JPL.NASA.GOV> Date: 6 Mar 91 23:47:20 GMT References: <1991Mar6.172554.14299@iwarp.intel.com> <124820@uunet.UU.NET> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 29 In article <124820@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim) writes: : In article <1991Mar6.172554.14299@iwarp.intel.com> merlyn@iwarp.intel.com (Randal L. Schwartz) writes: : >Watch this: : > : >Yow! The next exits the sub and cycles the outer "for" loop! (This : >bit me in a program today.) : : I say leave it in. This is like catch/throw or setjmp/longjmp. : As long as the subroutines are cleaned up ok, I'm all for it. I think the subroutine is cleaned up okay, but it's still rather presumptous of the subroutine to decide it was called from within a loop. And note that "next" is more or less equivalent to a return if there is a return statement in the subroutine, since return is implemented internally using a BLOCK. You'd still be able to say "next FILE", or whatever. Guess what this does: sub foo { return unless @_; print "I say, "; while ($_ = shift) { redo _SUB_ if /^;$/; print $_," "; } } &foo(now,is,';',the,time); Larry