Ronnie has asked for the wisdom of the Perl Monks concerning the following question:
#!/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" ;
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
"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
2006-10-04 Retitled by Corion, as per Monastery guidelines
Original title: 'Baffled'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing two files
by Corion (Patriarch) on Oct 04, 2006 at 12:20 UTC | |
|
Re: Comparing two files
by jdporter (Paladin) on Oct 04, 2006 at 14:38 UTC | |
|
Re: Comparing two files
by dorko (Prior) on Oct 04, 2006 at 15:43 UTC | |
|
Re: Comparing two files
by lyklev (Pilgrim) on Oct 04, 2006 at 20:08 UTC |