in reply to comparing lines in two files
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 | |
by bobr (Monk) on Jan 01, 2010 at 12:22 UTC | |
by ikegami (Patriarch) on Jan 01, 2010 at 22:26 UTC |