[Omaha.pm] next can jump out of a sub?

Miller, Scott L (Omaha Networks) scott.l.miller at hp.com
Tue Feb 1 12:56:49 PST 2005


I actually discovered one of my scripts was using this feature after I'd moved some
code into a subroutine, and forgot about dealing with the "next" statements...

   <digression> It also reminds me of an ugly construct I'd created in BASIC back in 
      high school.  Basically I ended up with an if, next, endif, for, goto sequence
      that placed the next before the for, and it worked.  I had a bit of a reputation
      for hideous spaghetti code after that one :)
   </digression>

-Scott

-----Original Message-----
From: omaha-pm-bounces at mail.pm.org
[mailto:omaha-pm-bounces at mail.pm.org]On Behalf Of Jay Hannah
Sent: Thursday, December 23, 2004 12:47 PM
To: omaha-pm at pm.org
Subject: [Omaha.pm] next can jump out of a sub?



Wow. What do you suppose this prints?

I thought it would (1) syntax error (next without loop) or (2) print 1 and then exit. 

I was wrong...

j


for (1..5) {
   print "$_\n";
   x();
   exit;
}

sub x {
   next;
}



_______________________________________________
Omaha-pm mailing list
Omaha-pm at mail.pm.org
http://www.pm.org/mailman/listinfo/omaha-pm


More information about the Omaha-pm mailing list