Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!agate!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Weird response of "next" inside sub? Message-ID: <1991Mar6.172554.14299@iwarp.intel.com> Date: 6 Mar 91 17:25:54 GMT Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 43 Watch this: for (1..5) { print "before $_...\n"; &marine(); print "after $_...\n"; } sub marine { print "begin marine\n"; next; #################### look here print "end marine\n"; } which prints: before 1... begin marine before 2... begin marine before 3... begin marine before 4... begin marine before 5... begin marine Yow! The next exits the sub and cycles the outer "for" loop! (This bit me in a program today.) I suspect that the "next" (as well as a last or redo) should be a syntax error at this point. I can't see why loop control statements should affect something out-of-scope. Does anyone currently use this (mis-)feature in a positive way? If not -- Larry, could you see about flagging this as an error? sub a {next;} {&a; redo;} print "Just another Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/