Update: Use chomp per tye's suggestionmy $matchBlock = do {local $/ = ""; <DATA>}; $/ = $matchBlock; @ARGV = ("file_to_inplace_edit.txt"); $^I = '.bak'; while (<>) { my $matched = chomp; print $_; #print everything up to the block to be replaced print "This replaces the matchBlock text\n" if $matched; } __DATA__ match string goes here. As long as you like and spanning lines if you like, but it must match exactly the text to be replaced including the line end characters in the file to be edited must be standard for the OS.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compact multi-line inplace file edit search and replace (:
by tye (Sage) on Aug 23, 2005 at 05:21 UTC | |
|
Re: Compact multi-line inplace file edit search and replace
by chanio (Priest) on Aug 23, 2005 at 06:18 UTC | |
by GrandFather (Saint) on Aug 23, 2005 at 07:40 UTC |