[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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@mail.pm.org
[mailto:omaha-pm-bounces@mail.pm.org]On Behalf Of Jay Hannah
Sent: Thursday, December 23, 2004 12:47 PM
To: omaha-pm@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@mail.pm.org
http://www.pm.org/mailman/listinfo/omaha-pm