in reply to comparing lines in two files

Hi,

If you want just know there was a change, go with File::Compare mentioned above.

I think you probably need to know what files were added and removed, in other word difference between your file list. You can try following approach:

First make sure your lists in files are sorted. Then use Text::Diff module like this:

use Text::Diff; my $diff = diff "saved_system.txt", "current_system.txt", { STYLE => " +OldStyle" }; my (@added,@removed); for(split /\n/,$diff) { next if /^\d/; # skip line numbers push @added,$1 if /^> (.*)$/; push @removed,$1 if /^< (.*)$/; } print "Added files:\n"; for my $file (@added) { print $file,"\n"; } print "\nRemoved files:\n"; for my $file (@removed) { print $file,"\n"; }

It prints output to console, but it is easy to change for printing into file.

-- hope this helps, Roman

Replies are listed 'Best First'.
Re^2: comparing lines in two files
by ikegami (Patriarch) on Jan 01, 2010 at 11:16 UTC
    It seems to me that will fail if saved_system.txt and current_system.txt are ordered differently.
      Agree completely, thats why I pointed that lists have to be sorted. Since this seems to be followup to storing all file info, I assumed that no problem make lists sorted on its creation.

      On any case, your solution below seems to be more elegant and independent on libraries.

      -- Roman

        sorry, I completely missed the bit about the lists being sorted