I'm not sure I understand exactly what you want as output, here's an alternate.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1136858 use Algorithm::Diff qw(traverse_sequences); use strict; use warnings; my @bigA = split /\n/, <<END; 111 abc 111 def 222 ghi 223 jkl 345 mno END my @bigB = split /\n/, <<END; 111 pqr 111 stu 111 vwx 222 yza 345 bcd END my @newfile; traverse_sequences( [ map /(...)/, @bigA ], [ map /(...)/, @bigB ], { MATCH => sub { print "$bigA[shift] $bigB[pop]\n" }, DISCARD_A => sub { push @newfile, my $left = $bigA[shift] . "\n"; print $left; }, DISCARD_B => sub { push @newfile, my $right = $bigB[pop] . "\n"; print ' ' x 10, $right; }, } ); print "\n\n", @newfile; #use File::Slurp; write_file 'newfilename', @newfile; # to make newfil +e
In reply to Re: Comparing two files and editing it.
by Anonymous Monk
in thread Comparing two files and editing it.
by rormonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |