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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp reading only first line 1

Status
Not open for further replies.

biobrain

MIS
Jun 21, 2007
90
GB
Dear All,

In my RegEx i have to match and print a statement from multiple files. And that statement may exist several time in those files but I want to match only the first matching line and ignoring the rest of all.

Is there any flag which i can use with my regexp which can tell to match print only first line.
 
use the "last" control:

Code:
while (<IN>) {
   if (/foo/) {
      last; #exits the "while" loop after the first match 
   }
}

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks a lot.

This is really working for me and solved the question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top