Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: pattern matching (greedy, non-greedy,...)

by Skeeve (Vicar)
on Dec 17, 2009 at 09:57 UTC ( #813163=note: print w/ replies, xml ) Need Help??

in reply to pattern matching (greedy, non-greedy,...)

I managed to use the range operator for this:

#!/bin/env perl use strict; use warnings; my $start= qr/^KEY$/; my $end = qr/^PATTERN$/; my $match; while (<DATA>) { if (my $hit= /$start/ .. /$end/) { $match= '' if /$start/; $match.= $_; print $match if $hit ne 0+$hit; } } __DATA__ KEY blah blahblah KEY blah ah other random stuff KEY blah ha other random stuff PATTERN asdf KEY fdas PATTERN

I simply reset my buffer when I find the start a second time.


Comment on Re: pattern matching (greedy, non-greedy,...)
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2015-07-29 07:59 GMT
Find Nodes?
    Voting Booth?

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

    Results (261 votes), past polls