tale051258 has asked for the wisdom of the Perl Monks concerning the following question:

I am using the diff command as follows
use Text::Diff; my $diff = diff "C:/after.txt", "C:/before.txt", { OUTPUT => \*DIFFILE +, STYLE => "Table" };

and I get the following in the file pointed to by DIFFILE:

+--+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+
| |C:/before.txt |C:/after.txt |
| |Thu Dec 22 12:00:23 2011 |Thu Dec 22 12:01:12 2011 |
+--+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+
* 1|MONA|Female|20610|Mother-In-Law |MONA|Female|20610|Lord Godess of the Universe * |
2|SAM|Male|13122|Doctor |SAM|Male|13122|Doctor | |
3|BOB|Male|11623|Accountant |BOB|Male|11623|Accountant |
+--+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+
The first line is definitely different between the files and should appear in the 'diff' table. But...
Question: Why do I get the next 2 lines back when they are identical?
These files that are being compared have exactly 1000 lines of which only the first line is visibly different. So the first line is the only one that should come back in the diff table.
Using Perl 5.14.2 on Win32
Cheers!

Replies are listed 'Best First'.
Re: diff not working as it should
by NetWallah (Canon) on Dec 23, 2011 at 16:23 UTC
    You did not specify a CONTEXT parameter.

    It defaults to 3.

    Changing your code to this will produce the desired output:

    my $diff = diff "after.txt", "before.txt", { OUTPUT => \*STDOUT, STYLE + => "Table", CONTEXT=>0 }; # Um - I used *STDOUT to test..

                "Battle not with trolls, lest ye become a troll; and if you gaze into the Internet, the Internet gazes also into you."
            -Friedrich Nietzsche: A Dynamic Translation

Re: diff not working as it should
by pvaldes (Chaplain) on Dec 23, 2011 at 16:25 UTC

    This is the only line different, and is the only marked with an asterisk. Don't count the line beginning with "||Thu..." this seems only a part of the title showing the timestamp of both files

    * 1|MONA|Female|20610|Mother-In-Law |MONA|Female|20610|Lord Godess of the Universe * |

    All the other lines are shown, but unmarked. You can change the format of your output in you don't like this.


      Yes, you've got my point there at the end of your response.
      I just want the one line with the asterisk to show (and the header at the top with the file names and dates). I want the other two lines (after the asterisk line) that are identical not to appear in the output. You mentioned I could do that by '... changing the format...'. How does one do that?
      Cheers!
        Play with the STYLE option, or simply apply a grep or a regexp m!(^\|\||^\*)! to the output line by line