Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-03-20 08:23 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.