Dear roboticus,
I tried the code and made some changes, mostly to see which files are stored where. The script worked in the test run, my next effort is to create a subroutine from that script, but before I do that I still have a question, since I really would like to understand what the code does.
I have a question about "trimming" the xml off as you nicely put it. The checking of the files does not raise an error, at least that is what I figure, since the errors messages are not printed out.
My question is how the script can differentiate between .xml and .bak. Would that be a built-in feature of the Text::Diff used in line 45? How exactly does the interpolation between file extension work in that particular case?
Would be grand if you or another monk could shed some light.
Thanks a mil in advance and kind regards
C.use 5.018; use strict; use warnings; use Data::Dumper; use File::Glob; use Text::Diff; use Text::Diff::Table; #Separating xml and backup files #my @xml_files = glob( '*xml' ); #say for @xml_files; #my @bak_files = glob( '*bak' ); #say for @bak_files; #Show differences between file_01.xml and file_01.xml.bak, etc... open my $FH, '>', "file_difference_report" or die $!; my @base_file_names_xml = map { s/\.xml$//; $_ } glob('*.xml'); print Dumper \@base_file_names_xml; my @base_file_names_bak = glob('*.bak'); print Dumper \@base_file_names_bak; #cutting off file extension to use file name only, extension for #comparing .xml and .bak added by code below; #print Dumper \@base_file_names; #print "\n\n\n"; for my $file_name ( @base_file_names_xml ) { if ( ! -e "$file_name.xml" ){ print "$file_name.xml: Not present ... not interesting file?\n +"; next; } if ( ! -e "$file_name.xml.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 to compare them for us: my $output = diff "$file_name.xml", "$file_name.xml.bak"; print $FH "\n\n===== $file_name changes =====\n"; print $FH $output; print $FH "\n\n"; }
In reply to Re^8: comparing contents of two arrays and output differences
by PitifulProgrammer
in thread comparing contents of two arrays and output differences
by PitifulProgrammer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |