Hello Perl Monks. I'm new to Perl and having a spot of bother. I'm trying to read in two data files which contain identical data but the data is out of order. I need to make sure the data from both files is in fact identical despite the order. The code I have so far is as follows:
#!/usr/bin/perl use strict; open (FILE, "exp.log") || die; my @array = <FILE>; close(FILE); print "\n\n\nExpected log read and stored"; open (FILE2, "actual.log") || die; my @array2 = <FILE2>; close(FILE2); print "\n\n\nActual log read and stored\n\n\n"; my @sorted = sort(@array); my @sorted2 = sort(@array2); if(@sorted eq @sorted2) { print "Success! Actual log and expected log contain the same data\ +n\n";} else { print "Failure! Actual log and expected log contain different dat +a\n\n"; } #print "@sorted\n"; print "\n\n\n\n\n\n\n\n\n-------------------------------------\n\n\n\n +\n\n"; #print "@sorted2\n"; exit;
a sample from one of the data files is as follows:
.MAMACACHE_REGRESSION.AGT.M Type: INITIAL Status OK MdMsgType | 1 | U8 | 1 MdMsgStatus | 2 | U8 | 0 MdSeqNum | 10 | U32 | 0 MamaAppMsgType | 18 | U8 | 0 MamaSenderId | 20 | U64 |6991275514488954478 .MAMACACHE_REGRESSION.BCO.M Type: INITIAL Status OK MdMsgType | 1 | U8 | 1 MdMsgStatus | 2 | U8 | 0 MdSeqNum | 10 | U32 | 0 MamaAppMsgType | 18 | U8 | 0 MamaSenderId | 20 | U64 | 6991275514488954478


The idea I had was to read in the two files, sort them (thus making the out of order a non issue)then compare the newly sorted array. However the problem I'm having is when i make subtle changes to one of the files (for eg changing a number from 20 to 19) the script still believes the two files are equal and only denotes a "failure" if the one of the text files has more lines introduced. Hope this makes sense. All the best!

In reply to Comparing unordered but similar data files by gwam

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.