You output to a third file. Let's fix that.
my $file_a = '...'; my $file_b = '...'; my %lines; { open my $fh, '<', $file_a or die "Can't open index file \"$file_a\": $!\n"; while (<$fh>) { $lines{$.} = 1 if /X/; } } { # Immitate "perl -pi". local $^I = ''; local @ARGV = $file_b; my $count = 0; while (<>) { s/(Y)/ exists $lines{ ++$count } ? 'Z' : $1 /eg; print; } }
Also fixed:
In reply to Re^2: This has me stumped, pattern matching, 2 files
by ikegami
in thread This has me stumped, pattern matching, 2 files
by tsk1979
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |