Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how to cut context between first "begin" and "end"?

by snoopy (Deacon)
on Sep 02, 2009 at 04:30 UTC ( #792803=note: print w/ replies, xml ) Need Help??


in reply to how to cut context between first "begin" and "end"?

One approach is to use a regular expression:

#!/usr/bin/perl use common::sense; my $data = join('', <DATA>); $data =~ s{(^|\n)begin\n # begin at start of string or line (.*?\n)*? # lines to skip (non-greedy) end\n} # matching end {$1begin\nend\n}sx; print $data; __DATA__ a begin 1 a 2 end c begin c end a begin 1
Update: added \n anchors and commented the regexp.


Comment on Re: how to cut context between first "begin" and "end"?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-07 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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









    Results (87 votes), past polls