Link to home
Start Free TrialLog in
Avatar of oostwijk
oostwijk

asked on

Check this out !!

Is it possible to get out of a foreach loop, without stopping the processing the rest of the script ? I've tried it with the exit and last function, and I've tried it using a label..
These lines I have so far :

foreach(@velden){
($veld1,$veld2,$veld3)=split(/,/,$_);
if ($form{$veld1}){
#### The foreach loop must be stopped here ####
&goed;
}else{
print "error";
return vulin;
}}

sub goed {
print "allright";
}

As you can see the loop must be stopped at the given location. I must use an foreach-loop otherwise I've got to rewrite my whole script.
Avatar of maneshr
maneshr

when you say "The foreach loop must be stopped here.." do you mean the processing should stop for a short time or the processing should end there.

if it is the later you should be fine with last.

Avatar of oostwijk

ASKER

well, the processing of the loop should stop, but the script must go on with sub goed. Give me the lines I should use..please.
you dont need any thing extra at all!! the code should do what you want as it is right now.

Nope, it does call the sub goed, as many times there are items in the @field. The sub goed, has to be called only ones.
let me get this straight now..

you have lets say 10 items in your array.

each time you check ..
if ($form{$veld1}){

if the above condition is true, you call goed.

Right???

now lets say of the 10 times that this loop is executed the if condition is true 4 times so goed will be executed 4 times.
But you want goed to be executed ONLY once, right???

if possible give me some raw data and also explain.
ASKER CERTIFIED SOLUTION
Avatar of lambda
lambda

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That does the job..