Hello all!

Actually I'm not sure how to defined my question based on specific title, I will try to explain more here then.

Text 1: Entry 1 1 N 2 D EOE
Text 2: Entry 3 6 N 7 EOE Entry 5 4 D 9 D EOE

Text 1 has 1 entry while text 2 has 2 entries. What I wish to do is to compare the contents of entry by entry between files and so on. For example above,both files have first entry then it will proceed to comparison. But, Text 1 does not contain second entry as Text 2 then output a warning message" Text 1 has missing content".

use strict; use warnings; my (@data1,@data2); my (@array,@array2); open my $fh, '<', 'Text1' or die "Could not open file to read:$!"; while (<$fh>) { if (/^\Entry (\w+)/../\EOE/){ push @array, $_; if (/^(\Entry)/){ push @data1 ,$1; } } } open $fh, '<', 'Text2' or die "Could not open file to read:$!"; while (<$fh>) { if (/^\Entry (\w+)/../\EOE/){ push @array2, $_; if (/^(\Entry)/){ push @data2 , $1; } } } print @array2; my $size = @data1 < @data2 ? @data1 : @data2; my $result= @data1 < @data2 ? "File 1 has missing data" : "File 2 has +missing data"; my $ori = @data1 == @data2 ? 1:0; my $i; for( $i = 0; $i < $size; $i++){ if ($data1[$i] ne $data2[$i]){ printf "%s is mismatch with %s\n",$data1[$i],$data2[$i]; } else { &compare(); } } print "$result\n" if (!$ori);

I do not include the subroutine here. I would like to ask if any idea to store content of each entry specifically to ease the comparison work? I have tried array but it stores content of all entries as it has. Instead access to the content of entry 3, it access to all content of text 2. Is hash able to do so? Any suggestion is much appreciated. I am not expecting any codes but some suggestion on which functions or method would really be a big help. I am trying to write Perl myself. Cheers.


In reply to Methods to store content by annel

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.