Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Weird response of "next" inside sub? Message-ID: <1991Mar09.200039.1484@convex.com> Date: 9 Mar 91 20:00:39 GMT References: <1991Mar6.172554.14299@iwarp.intel.com> <222@munz.UUCP> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 32 Nntp-Posting-Host: pixel.convex.com From the keyboard of nagler@olsen.ch (Rob Nagler): :In article <1991Mar6.172554.14299@iwarp.intel.com> merlyn@iwarp.intel.com (Randal L. Schwartz) writes: :>Yow! The next exits the sub and cycles the outer "for" loop! :>Does anyone currently use this (mis-)feature in a positive way? : :I often use the aformentioned feature as follows: sigh. probably can't get rid of it then. still, it gives me the willies. : :sub err { print STDERR "$f: $_[0]: @!\n"; next; } you mean, $!, not @!, i think. :for $f (@files) { : open(FILE, $f) || &err("open"); : print FILE "something\n" || &err("print"); : close(FILE) || &err("close"); :} : :You could turn this into one expression or put a next on every line. :However, I always take Larry's advice: "Perl is designed to give :you several ways to do anything, so consider picking the most :readable one." BTW, why doesn't "next $l" work? (do you mean "next $f"?) one answer is that next takes a label as an operand, not a scalar. as for why this should be so, i dunno -- ask larry. :-) --tom