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

Hi I am a new comer to Perl with only limited Perl skills (but really want to improve!). At the moment I am trying to compare two files then modify one of the files with the differences found (actually only some of the differences). Is this possible? if so does anyone know how? Any help anyone could give would be fanatastic. Thanks again from one frustrated Perl user

Replies are listed 'Best First'.
Re: Compare files and copy differences
by rob_au (Abbot) on Jan 17, 2002 at 04:37 UTC
    The module which you should have a look at is Algorithm::Diff originally written by Dominus, now maintained by bikeNomad. Included with this module are the example programs diff.pl and cdiff.pl, the latter of which produces a differential output suitable for use with patch.

    Also have a look at the homepage for this module here.

     

    perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Re: Compare files and copy differences
by FoxtrotUniform (Prior) on Jan 17, 2002 at 04:28 UTC

    If you're doing this on a Unix-like operating system, or on Win32 with Cygwin, have a look at the diff(1) command. You'd probably be better off reading diffs and working with their output than reinventing the wheel. You might also look in CPAN for diff-related modules.

    --
    :wq
      Not an Perl solution, but if you're on a Win32 platform, I highly recommend using a tool called BeyondCompare(http://www.scootersoftware.com/)...

      Ok ok it's not free, but there is an eval version, and it has a lot of nifty features.

Re: Compare files and copy differences
by jlongino (Parson) on Jan 17, 2002 at 04:37 UTC
    As FoxtrotUniform noted you might try CPAN first since they're probably vetted already, if you don't have any luck there, Super Search on "file compare diff" turned up several nodes--one of which is Comparison of files.

    --Jim

    Update: corrected the last link.