in reply to replacing text in multiple files
or# Edit-in-place in multiple files - one file at the time { local $^I = q{}; local @ARGV = @files; while(defined(my $line = <>)){ # do something with $line } continue { print $line; } }
# Read multiple lines from multiple files at the same time my @files = @ARGV; my @fh; my $i = 0; foreach my $file (@files) { -f -r $file or next; open $fh[$i++], '<', $file or die "Cannot open $file: $!"; } while (1) { my @lines; foreach my $i (0 .. $#fh) { ref $fh[$i] eq 'GLOB' or next; push @lines, scalar readline $fh[$i]; if (eof $fh[$i]) { close $fh[$i]; $fh[$i] = undef; } } @lines or last; foreach my $line (@lines) { # do something with $line } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: replacing text in multiple files
by Anonymous Monk on Apr 14, 2012 at 00:12 UTC | |
by Anonymous Monk on Apr 14, 2012 at 02:35 UTC |