I suspect the issue is because you are using chop instead of chomp. If your input files are not newline terminated, your chops will remove data values from the terminating entry. The code:

#!/usr/bin/perl use strict; use warnings; my @file1 = qw( 1.10.10 1.10.1040 1.10.150 1.10.220 ); my @file2 = qw( 1.10.10.640 1.10.10.650 1.10.10.660 1.10.1040.20 1.10.150.290 1.10.150.300 1.10.150.310 1.10.220.80 ); for(my $i=0; $i<@file1; $i++) { chomp($file1[$i]); #print "F $file1[$i]"; for(my $j=0; $j<@file2; $j++) { chomp($file2[$j]); my @array = split(/\./, $file2[$j]); my $cat = "$array[0]" . "." . "$array[1]" . "." . "$array[2]"; if("$file1[$i]" eq "$cat") { print "$file1[$i] $cat\n"; } } }

(with null-op chomps) yields the result

1.10.10 1.10.10 1.10.10 1.10.10 1.10.10 1.10.10 1.10.1040 1.10.1040 1.10.150 1.10.150 1.10.150 1.10.150 1.10.150 1.10.150 1.10.220 1.10.220

which seems to my eyes to be the spec. There are some stylistic modifications I would implement (Foreach Loops, hash instead of iterating with eq), but this should fix your bug.

Update: I'd missed that you were chopping in an inner loop, as ikegami notes below. The bug fix still holds.


In reply to Re: help requested with collating data from two files by kennethk
in thread help requested with collating data from two files by Angharad

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.