Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Comparing two files and editing it.

by Anonymous Monk
on Jul 31, 2015 at 00:41 UTC ( [id://1136957]=note: print w/replies, xml ) Need Help??


in reply to Comparing two files and editing it.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1136957]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found