Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 chilling in the Monastery: (6)
As of 2015-11-28 17:05 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls