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 romping around the Monastery: (4)
As of 2015-11-27 07:20 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 (719 votes), past polls