Hello
lonnie,
I'm not sure that I completely understand your example. The data in GoodFile.txt and BadFile.txt differ on line 2, so I would expect that difference to show up in Output.txt. However, in your example it does not.
Here is some code that uses Algorithm::Diff to calculate the diff, with some help from Path::Tiny to get the file contents.
This code,
#!/usr/bin/env perl
use strict;
use warnings;
use Path::Tiny;
use Algorithm::Diff qw/diff/;
my @lines1 = path('GoodFile.txt')->lines;
my @lines2 = path('BadFile.txt')->lines;
my $diff = Algorithm::Diff->new( \@lines1, \@lines2 );
while( $diff->Next() ){
next if $diff->Same();
print $diff->Items(2), "\n";
}
exit;
gives the following output:
This section is the description of the animal bla bla lbas.....bla bla
+ lbas.....
Amimal, cat, 3, 4, YELLOW LEG 3, HIGH 'this is a cattt 1
This section is the description of the animal bla bla lbas.....bla bla
+ lbas blaaaal........
UPDATE: The OP made edits to their node, and removed their input data. Here is the input data that I used for my code example (which the OP had provided in the first version of their post).
GoodFile.txt
Amimal, cat, 1, 4, YELLOW HAIR 3, HIGH 'this is a cattt 1
This section is the description of the animal bla bla lbas.....
Amimal, dog, 2, 4, BLACK HEAD 1, HIGHf'this is a doggg 2
This section is the description of the animal bla bla lbas.....
BadFile.txt
Amimal, cat, 1, 4, YELLOW HAIR 3, HIGH 'this is a cattt 1
This section is the description of the animal bla bla lbas.....bla bla
+ lbas.....
Amimal, cat, 3, 4, YELLOW LEG 3, HIGH 'this is a cattt 1
This section is the description of the animal bla bla lbas.....bla bla
+ lbas blaaaal........
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.