Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Multiline search and replace in file(s)

by AnomalousMonk (Archbishop)
on Aug 09, 2020 at 08:18 UTC ( [id://11120516]=note: print w/replies, xml ) Need Help??


in reply to Multiline search and replace in file(s)

Note that this will deal with Mary and her little lamb over any line boundaries:

c:\@Work\Perl\monks>perl use strict; use warnings; use autodie; my $data = <<EOD; Mary Had A Little Lamb She Was GOOD Not Changing this Or This Mary Had A Little Lamb She Was GOOD Line 9 Line 10 EOD open my $fh, '<', \$data; my $content = do { local $/; <$fh>; }; print "[[$content]] \n\n"; $content =~ s{ Mary \s+ Had \s+ A \s+ Little \s+ Lamb \s+ She \s+ Was \s+ GOOD } {CHANGED!!!}xmsg; print "<<$content>> \n"; __END__ [[Mary Had A Little Lamb She Was GOOD Not Changing this Or This Mary Had A Little Lamb She Was GOOD Line 9 Line 10 ]] <<CHANGED!!! Not Changing this Or This CHANGED!!! Line 9 Line 10 >>


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found