use strict; use warnings; use File::Copy; my($replacePattern1) = "foo1"; my($searchPattern1) = "bar1"; my($replacePattern2) = "foo2"; my($searchPattern2) = "bar2"; my($replacePattern3) = "foo3"; my($searchPattern3) = "bar3"; my $pattern = 0; my $list = 'list.txt'; open my $fh, '<', $list or die "can not open $list: $!"; my @files = <$fh>; close $fh; chomp @files; for my $file (@files) { my $copy = "$file.bak"; copy($file, $copy) or die "File $file cannot be copied: $!\n"; open my $fhi, '<', $copy or die "can not open $copy: $!"; open my $fho, '>', $file or die "can not open $file: $!"; while (<$fhi>) { if (s/$searchPattern1/$replacePattern1/g) { $pattern = 1; } elsif (s/$searchPattern2/$replacePattern2/g) { $pattern = 2; } elsif (s/$searchPattern3/$replacePattern3/g) { $pattern = 3; } print $fho $_; } close $fho; close $fhi; unlink $copy; }
In reply to Re: Find and Replace from File List
by toolic
in thread Find and Replace from File List
by PyrexKidd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |