Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

match across specified # of lines

by bill b (Initiate)
on Jun 13, 2013 at 14:35 UTC ( #1038753=perlquestion: print w/ replies, xml ) Need Help??
bill b has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I need to search for

.PP

blah blah blah

.PP

How do I search across 3 lines exactly? This didn't work

/^\.PP.*\n.*\n^\.PP/

TIA,

Bill

Comment on match across specified # of lines
Re: match across specified # of lines
by Anonymous Monk on Jun 13, 2013 at 14:38 UTC

    This didn't work

    Of course :) it doesn't read a file, or set the value of $_ in any way, so $_ is undef, and then there is nothing to match, so the matching doesn't work

    You need to examine the value of $_, Data::Dump/er it , its Basic debugging checklist

      Thanks for the pointer!
Re: match across specified # of lines
by hbm (Hermit) on Jun 13, 2013 at 14:43 UTC

    Make your dot-stars non-greedy, and use the 'm' modifier:

    $_=" Blah junk .PP blah more stuff .PP boo razz "; print $1 if /^(\.PP.*?\n.*?\n\.PP)/m; #prints .PP blah more stuff .PP
      Thanks! That worked! I did have the m appended but forgot to type it. Your solution really helped a lot. Cheers!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2015-07-05 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls