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

Hi perl monks, I'm new to perl, I need to generate diff file using Text::Diff using activeperl 5.10 in windows(my workplace).I have read the Text::Diff cpan page but doesn't help me alot.

Here's the code:

#diffgen.pl use warnings; use strict; use Text::Diff; print "test test... \n"; my $diff = diff "./Project1/include/jcapi_includes.h", "./Project1/2.1/include/jcapi_includes.h", { STYLE => "Unified" }, ( OUTPUT => "./result.diff" );

When I run perl diffgen.pl it only shows
test test...
but the file result.diff is not generated. Can someone enlighten me here? Thanx

Replies are listed 'Best First'.
Re: Using Text::Diff in windows perl (activeperl) ??
by lamp (Chaplain) on Sep 01, 2008 at 09:44 UTC
    Hi
    as per the Text::Diff module specification, you cannot pass a file name directly as OUTPUT. For printing the diff result to a file, you need to pass a file handler as OUTPUT. Please check the following updated code
    use warnings; use strict; use Text::Diff; open (FHANDLE, ">result.diff"); print "test test... \n"; my $diff = diff "./test.txt", "./test1.txt", { STYLE => "Unified" , OU +TPUT => \*FHANDLE }; close(FHANDLE);
    --lamp

      Oops..sorry. Yes,lamp that works! Thank you!! Anyway, forgot to tell that the reason I don't use windows gnu diff is I have to minimize dependency, you know corp. constraint..I try to make so that the users would only required to have activeperl (and better for them to use additional perl module than another external program. Really) to run my script and a visual compare/diff tool(this is different story to tell) that they already have.

      Now what I'm curious is why anonymous monk's reply suggest using Algorithm::Diff and a different perl script. CMIIW, but I thought Text::Diff also use Algorithm::Diff no? what's the difference the perl script that he/she links to and Text::Diff? which one should I use? Or should I use Text::Diff3 (I don't know how to compare 2 files only using Text::Diff3 though)

Re: Using Text::Diff in windows perl (activeperl) ??
by Anonymous Monk on Sep 01, 2008 at 08:57 UTC