May be you can try to read data in hash first as it is an index data, then match key to it and add the value. I am assuming your master data in the format that you have provided.

#!/usr/bin/perl -w use strict; my $file1 = "file1.txt"; my $file2 = "file2.txt"; my %hash = (); my %ahash = (); open F1, $file1 or die "Can't open $file1 $!"; open F2, $file2 or die "Can't open $file2 $!"; while(<F1>){ my $line = $_; chomp($line); $hash{$line} = $line; } while(<F2>){ my $line = $_; chomp($line); (my $w1, my $w2) = split(/ +/, $line); $ahash{$w1} = $w2; } # Matching of two Hash for ( keys %hash ) { unless ( exists $ahash{$_} ) { print "$_: not found in second hash\n"; next; } if ( $hash{$_} eq $ahash{$_} ) { print "$_: values are equal\n"; # Do something with the value } else { print "$_: values are not equal\n"; } }

Might be it will give you an idea to compare files data using hash.


In reply to Re: Better way to search an Array? by akuk
in thread Better way to search an Array? by doubleqq

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.