When Richard_K mentioned "shell out to `diff`" he didn't mean for the user to use diff manually, but for your program to do the work of creating the command line and running it for the user to get the desired results. Consider this:
open my $FH, '>', "file_difference_report" or die $!; my @base_file_names = ( 'file1', 'file2', 'file3', 'file4' ); for my $file_name (@base_file_names) { if (! -e "$file_name.xml") { print "$file_name.xml: Not present ... not interesting file?\n"; next; } if (! -e "$file_name.bak") { print "$file_name: no backup, so probably not changed\n"; next; } # If we get here, we have a .bak and a .xml file, so make another +program # compare them for us: my $output = `diff $file_name.xml $file_name.bak`; print $FH "\n\n===== $file_name changes =====\n"; print $FH $output; print $FH "\n\n"; }
In the line starting "my $output", we shelled out to use the diff command to compare the files and store the result in $output. From there you can do what you want with the results, such as concatenate it to the end of a report, as done here.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re^5: comparing contents of two arrays and output differences
by roboticus
in thread comparing contents of two arrays and output differences
by PitifulProgrammer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |