Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Grepping with Perl: How to stop after first match?

by fenLisesi (Priest)
on Dec 06, 2007 at 10:48 UTC ( #655356=note: print w/ replies, xml ) Need Help??


in reply to Grepping with Perl: How to stop after first match?

Some secondary points:

  • I think # is not the best delimiter.
  • dot in a default regex does not match a newline, so you probably don't need the last \n in there (Update: if you make the dot-star greedy)
  • Did you slurp the file? If not, what is your input record separator? Depending on the structure of the file and whether you are doing other matches with the data, you may be able to make use of the input record separator to simplify your regex.
  • I would recommend an if block, but if you want to use and for flow control, consider putting the and at beginning of the second line
  • What is the purpose of (.*?)


Comment on Re: Grepping with Perl: How to stop after first match?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://655356]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2015-06-04 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What kind of chocolate gives you the most pleasure?















    Results (143 votes), past polls