Solved

Check this out !!

Posted on 2000-04-04
7
149 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:oostwijk
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2685442
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.

0
 

Author Comment

by:oostwijk
ID: 2685567
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.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2685656
you dont need any thing extra at all!! the code should do what you want as it is right now.

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:oostwijk
ID: 2685673
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.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2685706
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.
0
 
LVL 1

Accepted Solution

by:
lambda earned 45 total points
ID: 2686237
put 'last' after &goed;


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

sub goed {
print "allright";
}
0
 

Author Comment

by:oostwijk
ID: 2687956
That does the job..
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now