Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!spool.mu.edu!uunet!mcsun!cernvax!chx400!chx400!olsen!nagler From: nagler@olsen.UUCP (Rob Nagler) Newsgroups: comp.lang.perl Subject: Re: Weird response of "next" inside sub? Message-ID: <222@munz.UUCP> Date: 9 Mar 91 16:13:13 GMT References: <1991Mar6.172554.14299@iwarp.intel.com> Reply-To: nagler@olsen.ch (Rob Nagler) Organization: Olsen & Associates, Zurich, Switzerland Lines: 20 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: sub err { print STDERR "$f: $_[0]: @!\n"; next; } 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? $_='$_="Just another Perl";redo';{eval;$_.=' hacker,';}s,\S+\,,\U$&,,print; Rob nagler@olsen.ch