in reply to Large scale search and replace with perl -i
use File::Find; @ARGV = (); find sub { push @ARGV, $File::Find::name if -f and /\.html$/; }, "."; { local $^I = ".bak"; local $/; while (<>) { if (s/foo/bar/g) { # changes? print; # print the new one } else { # no changes? back it out! close ARGVOUT; # for windows, not needed on Unix rename "$ARGV$^I", $ARGV or warn "Cannot rename for $ARGV$^I: $! +"; } } }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: •Re: Large scale search and replace with perl -i
by BrowserUk (Patriarch) on Apr 20, 2003 at 07:23 UTC | |
by merlyn (Sage) on Apr 20, 2003 at 15:37 UTC |