Dear roboticus

Thanks a mil for clarifying RichardK's example and for providing a code sample. I like the approach and I think this might be the way to go ( might look nicer to the user, although I personally prefer tables ).

Be that as it may, I have one question that cropped up, while I was trying the code. In your example the files for the array are hardcoded. Since in the application scenario(s) the amount of files will vary. So I need to read the files into an array.

When using my previous approach with the glob function, the file names do not match, i.e. the script checks for

file_02_0.xml.xml: file_03_0.xml.xml: file_04_0.xml.xml: file_05_0.xml.xml:

and with the .bak files, the script checks for:

file_02_0.xml.bak.xml: file_03_0.xml.bak.xml: file_04_0.xml.bak.xml: file_05_0.xml.bak.xml:

I would like to turn this piece of code into a subroutine which will be implemented into another script, so I guess I cannot hardcode the file names, nor pass via cmd. Secondly, the xml files might be used for further processing so I would like to keep them separate.

I have been wrecking my head how to get around the issue, but no matter what I used I have not been successful. Moreover, I think I cannot change the the file tests for .bak and .xml, since what would be there to check, right?. Is there any way I could keep the file test and using glob and/or File::Find::Rule to keep both file types separate while still doing the comparision as shown here?

I know that I am missing something quite elemental, but I could not figure it out, please excuse my stupidity.

Thanks a mil for your help, I am really learning a lot more than just going through one book after the other

Kind regards

C.
#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_files, @bak_files ); print Dumper \@base_file_names; print "\n\n\n"; 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 to 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 reply to Re^6: 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.