Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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:


I need to search for


blah blah blah


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




Replies are listed 'Best First'.
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!
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!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2016-10-22 17:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (297 votes). Check out past polls.