xorl has asked for the wisdom of the Perl Monks concerning the following question:
I'm looping through the contents of an array.
Before each iteration of the loop is completed, I want a couple of things done (increment a count, print some debug info, and a few other things). There are a number of conditions that cause the loop to move on to the next one early so my though is to put these into a subroutine and call that. However, one of these things is:
if ($x > $stop) { last; } elsif ($y ne $text) { foobar(); } else { next; }
So of course I get the warning "Exiting subroutine via last" (or next)
Is there a good way of doing this without having to put that snippet of code into every place where I need to move the loop forward?
Update: hexcoder with the continue block is exactly what I need. Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: next and last within subs
by Laurent_R (Canon) on Jul 11, 2014 at 20:43 UTC | |
|
Re: next and last within subs
by hexcoder (Curate) on Jul 12, 2014 at 17:45 UTC | |
|
Re: next and last within subs
by toolic (Bishop) on Jul 11, 2014 at 19:38 UTC | |
by xorl (Deacon) on Jul 11, 2014 at 19:58 UTC | |
by oakb (Scribe) on Jul 11, 2014 at 21:36 UTC | |
by Anonymous Monk on Jul 11, 2014 at 20:25 UTC | |
|
Re: next and last within subs
by RonW (Parson) on Jul 11, 2014 at 20:08 UTC | |
|
Re: next and last within subs
by BillKSmith (Monsignor) on Jul 12, 2014 at 04:09 UTC |