I've been tasked with a rather large software update task and have hit a road-bump at the first hurdle which is baffling me - not hard to do and I've had a very bad week! I want to compare 2 files which contain among things PC numbers. I want to compare the new list with the old and extract the names of the new PC's that have been added since the last run. Simple I hear you say, well I thought so. The following code tells me every PC is new - working for a Council I KNOW that's simply not true!
#!/usr/bin/perl -w # use strict ; # # # Scalars #---------# my $count_in = 0 ; my $count_new = 0 ; my $file_new = 'PC_LIST_20060919.txt' ; my $file_old = 'Prev_carefirst_PCs.txt' ; my $PC_NO = undef ; # # Arrays #--------# my @fields = () ; # # Boolean #---------# my $FOUND = 0 ; # # Processing #------------# print "\n\t\t\t\tTest Starts\n" ; open IN1, "<$file_new" or die "\n\tCanny open $file_new :: $!\n" ; while (<IN1>) { chomp ; $count_in ++ ; @fields = split /,/, $_ ; $PC_NO = $fields[1] ; $FOUND = 0 ; open IN2, "<$file_old" or die "\n\tCanny open $file_old :: $!\n" ; while (<IN2>) { chomp ; if (/($PC_NO)/) { print "\n\tIt matched!!!\n" ; $FOUND = 1 ; } } close IN2 or die "\n\tCan't close $file_old :: $!\n" ; if (! $FOUND) { print "\n\tPC $PC_NO is new!" ; $count_new ++ ; } } close IN1 or die "\n\tCan't close $file_new :: $!\n" ; print "\n\tThere were $count_in PC's checked!" ; print "\n\tThere were $count_new new PC's found!" ; print "\n\t\t\t\tTest Ends\n" ;

The files being read were a csv file saved from an Excel spreadsheet (The new list) and a txt file saved from an access table (The old list).
The NEW list looks like
Priority Kirkgate, PC7588 Priority Kirkgate, PC7598 Priority Kirkgate, PC8590 Priority.CD Site's, PC8648 Priority.CD Site's, PC8756 Priority.CD Site's, PC9020 Priority.CD Site's, PC9028 Priority.CD Site's, PC9093

The old list looks like
"B5206","128.1.36.205","000C765D5E68","CN=PC7607.OU=Workstations.O=abe +rdeen.T=ABERDEEN" "PC10018","128.1.37.13","0011090675AA","CN=PC10018.OU=Workstations.O=a +berdeen.T=ABERDEEN" "PC10152","128.1.40.30","000C76EFD05F","CN=PC10152.OU=Workstations.O=a +berdeen.T=ABERDEEN" "PC10171","128.1.13.57","000C76EFD027","CN=PC10171.OU=Workstations.O=a +berdeen.T=ABERDEEN" "PC10266","128.1.38.195","0011092581AB","CN=PC10266.OU=Workstations.O= +aberdeen.T=ABERDEEN" "PC10335","128.1.34.213","0011092582CE","CN=PC10335.OU=Workstations.O= +aberdeen.T=AB

The strange thing is that I thought it was my logic that was wrong but if I create a couple of dummy new & old files with just one entry in each it works fine! Any ideas what I'm failing to understand here?

2006-10-04 Retitled by Corion, as per Monastery guidelines
Original title: 'Baffled'


In reply to 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.