Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: how to extract text between 2 strings on separate lines

by Eily (Curate)
on Nov 13, 2013 at 16:27 UTC ( #1062411=note: print w/ replies, xml ) Need Help??


in reply to how to extract text between 2 strings on separate lines

Look at the precedence of operators, =~ is of higher precedence than ... So $record=~ /^start\b$/ .. /^end\b$/ is interpreted as (scalar $record =~ /^start\b$/) .. (scalar /^end\b$/) (in this case the scalar keyword doesn't change the result, so you can pretend they are not there to make it clearer). So you actually have: (scalar $record =~ /^start\b$/) .. (scalar $_ =~ /^end\b$/) because match operations work on $_ by default.

while (<CHECKBOOK>) { if (/^start\b$/ .. /^end\b$/) { print MYOUTFILE "$file;$_\n"; } }
should work better. Or $record =~ /^start\b$/ .. $record =~ /^end\b$/ if you want to use $record, but that looks more noisy.


Comment on Re: how to extract text between 2 strings on separate lines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2015-07-28 01:29 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 (251 votes), past polls