You haven't printed out the strings you're trying to compare:

$_ = "Priority Kirkgate, PC7588\n"; @fields = split /,/, $_ ; print "PC string from NEW list: >>$fields[1]<<";

This code will have your PC code with a leading space, and the rest of your code won't match that.

Also, it's not really efficient to read through the $old_file for every comparison. I'd read new computers into a hash and then check while stepping through $old_file whether the computer is known or not:

use strict; my %new_pc; ... while (<IN1>) { chomp; $count_in++; @fields = split /,/, $_; $PC_NO = $fields[1]; $PC_NO =~ s/\s*//g; $new_pc{ $PC_NO } = 1; }; ... while (<IN2>) { chomp; if (/CN=(PC\d+)\.OU/) { my $pc = $1; if (exists $new_pc{ $pc }) { # $pc is old and new, hence has survived delete $new_pc{ $pc }; } else { # $pc is old but not new, hence has been removed }; } else { warn "Ignoring line >>$_<<"; }; }; # All PCs in %new are now really new: for my $pc (keys %new) { print "$pc is new\n"; };

In reply to Re: Comparing two files by Corion
in thread Comparing two files by Ronnie

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.