in reply to next'ing out of a "foreach" loop within a subroutine
"Is there a way to get the "foreach" loop to go to the next array element from within the subroutine?"
Whether this is possible is irrelevant, as this is a bad idea any way. It is a bad idea as it breaks the modulization.
In your demo code, that next is useless any way.
By the way, your routine never took the parameter passed in.
Just to tame your curiosity, try this for once, but never use it in your real code:
use strict; use warnings; my @array = (9 .. 11); foreach my $row (@array) { &routine($row); } sub routine { my $row = shift; if ($row != 10) { print "stuff"; } else { last; } }
This prints only one "stuff", so that that last actually ended the foreach loop.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: next'ing out of a "foreach" loop within a subroutine
by awohld (Hermit) on Oct 30, 2005 at 04:19 UTC | |
by pg (Canon) on Oct 30, 2005 at 04:30 UTC | |
by ysth (Canon) on Oct 30, 2005 at 05:56 UTC |