473,408 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Is there any command to come out of the loop?

Hi,
I tried the following code.I m trying 2 compare two strings.If its not matches, the while loop has to continue and if it matches, it will come out of the while loop.
But In my code, Even it matches the while loop continuing.
can anybody tell me where I am wrong?

Expand|Select|Wrap|Line Numbers
  1. $flag=1;
  2. LINEP:
  3. while ($flag==1) {
  4.     print"Enter the lun name\n";
  5.     chomp($lunname=<stdin>);
  6.     foreach $line (@weblist) {
  7.         if ($line =~ m/$lunname/i) {
  8.             $flag=0;
  9.             print " found";
  10.             redo LINEP;
  11.         } else {
  12.             $flag=1;
  13.             redo LINEP;
  14.         }
  15.  
  16.     }
  17. }
  18.  
Thanks and Regards,
susi
Jun 28 '07 #1
5 4324
KevinADC
4,059 Expert 2GB
You posted in the perl articles area.

If you want out of the loop, why are you using "redo"? Maybe you should use "last".

if ($line =~ m/$lunname/i) {
print " found";
last LINEP;

}
Jun 28 '07 #2
Hi Kevin,

Yes, Last is working fine to come out of the loop
But I want to loop again for invalid inputs.

Thanks,
Susi.
Jun 28 '07 #3
alcazar
10
Use "next" to go back to beginning of loop
Jun 28 '07 #4
KevinADC
4,059 Expert 2GB
Hi Kevin,

Yes, Last is working fine to come out of the loop
But I want to loop again for invalid inputs.

Thanks,
Susi.
last - exits loop
next - goes to next iteration of loop
redo - does the same loop over again

you figure out which loop control you need to use.
Jun 28 '07 #5
Hi ,

Thanks for your valuable information.
Now I understand.Where I have to use these.

Thanks and Regards,
Susi.
Jun 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ben Floyd | last post by:
It goes like this: Im converting a perl script that executes a command on each result of a directory listing. In perl, all is well. In Python, using approximately the same logic creates a...
8
by: bearophileHUGS | last post by:
Hello, I have four things to ask or to suggest, sorry if they seem basic or already discussed. ------------------- I am still ignorant about Tkinter. This little program, after pressing the...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
0
by: ME | last post by:
I have a need to generate both the DLL version of my application and an EXE version. I would like to build both of them with a single call "build". One of the ideas I have come up with is to...
41
by: c | last post by:
Hi every one, Me and my Cousin were talking about C and C#, I love C and he loves C#..and were talking C is ...blah blah...C# is Blah Blah ...etc and then we decided to write a program that...
40
by: =?Utf-8?B?Um9iZXJ0IEUuIEZsYWhlcnR5?= | last post by:
What is the C# command to wait for a specified period of time? I am writing a windows service that will process a file once it has beed created or changed. I'm using the fileSystemWatcher to...
2
beacon
by: beacon | last post by:
Hi everybody, I've searched and searched for the answers to these questions until I've turned blue in the face, so I finally decided to come here for some assistance. Here's the info I'm...
16
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.