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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.