Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding a string in a text file in perl

Status
Not open for further replies.

bcdixit

Technical User
Nov 11, 2005
64
US
I want to search for a particular string in a text file.

I was trying to open the file for read and use a while loop to search for the string line by line. I want to stop at the first match but I dont know how to exit from the while loop after the match.
could anybody help?

any other solutions are also welcome.

thnks
-bcd
 
To exit out of your while loop, take a look at last.
 
a short example:

Code:
while(<>){
   if (condition) {
      print $_;
      last;
   }
}

- Kevin, perl coder unexceptional!
 
thanks kevinADC, thats exactly what I was doing. I did not know about the "last" function.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top