
arokiamary
New User
Sep 8, 2011, 3:52 AM
Post #1 of 2
(2669 views)
|
|
pattern match is not working globally
|
Can't Post
|
|
Hi I am new to Perl below is my script for comparing two text files(LEAP_O.txt,VLDB_O.txt) and printing the difference. pattern matching is working in the first occurrence. Could you please guide me where i am going wrong. Dealing with data of a-z series,some series contain more than 500 lines. below given my sample input from o series and the script. my requirement is need to print the difference at the same time for some criteria need to ignore. Example for ignoring: COMMITED PLACES ORDER, Map. 213, Order 1 ------> VLDB_O.txt Commited Places Order, Map. 213, OR 1 ------> LEAP_O.txt COMMITMENT OF COMPETENT AUTHORITY, Map. 213, Notification 1 ------> VLDB_O.txt Commitment of Competent Authority, Map. 213, N 1 -->LEAP_O.txt Script(working in the first occurence) #!/usr/bin/perl #use strict; use warnings; open(FILE,'>C:\\Aolvldbcomp\\Difference.txt'); my ($names, $data) =('LEAP_O.txt','VLDB_O.txt'); open (FILE1,$names) || die; open (FILE2,$data) || die; my @leapStrings = <FILE1>; chomp (@leapStrings); close(FILE1); my @vldbStrings = <FILE2>; chomp (@vldbStrings); close(FILE2); for my $leapString (@leapStrings){ print FILE "$leapString"; $leapString =~ s/^\s+//; $leapString =~ s/\s+$//; my $found = 0; for my $vldbString (@vldbStrings){ $vldbString =~ s/^\s+//; $vldbString =~ s/\s+$//; $vldbString =~ s/Notification\s+(\d+)\s*$/N $1/g; $vldbString =~ s/Order/OR/g; if (($leapString) =~ m/$vldbString/i) { $found = 1; last; } } if ($found) { print FILE "\t FOUND IN VLDB =====\n"; } else { print FILE "\t NOT FOUND IN VLDB =====\n"; } } close(FILE); VLDB_O.txt (input file) JOINTS AND COMMITMENT JOINTS AND cOMMITMENT (PRESCRIBED FORMAT) REGULATIONS, Map. 211, Regulation 1 PRACTICAL ORDER COMMITED PLACES ORDER, Map. 213, Order 1 COMMITMENT OF COMPETENT AUTHORITY, Map. 213, Notification 1 COMMITED OF COMPETENT AUTHORITY, S 417/1998 COMMITED PLACES ORDER 1997, S 276/2000 JOINTS AND OPTICIANS JOINTS AND OPTICIANS (REGISTRATION AND PRACTISING CERTIFICATES) REGULATIONS, Map. 213A, Regulation 1 JOINTS AND OPTICIANS (INVESTIGATION OF COMPLAINTS) REGULATIONS, Map. 213A, Regulation 2 JOINTS AND OPTICIANS (PRACTICE, CONDUCT, ETHICS AND PUBLICITY) REGULATIONS, Map. 213A, Regulation 3 JOINTS AND OPTICIANS (EXEMPTION FROM SECTION 25(1)) ORDER, Map. 213A, Order 1 JOINTS AND OPTICIANS (COMMENCEMENT) NOTIFICATION 2008, S 89/2008 LEAP_O.txt (inputfile) Joints and Commitment Practical Order Commitment of Competent Authority, Cap. 213, N 1 Commited Places Order, Cap. 213, OR 1 Prohibited Places Order 1997, S 276/2000 committed Places Order 2001, S 538/2010 Joints and Opticians Joints and Opticians (Exemption from Section 25(1)) Order, Map. 213A, OR 1 Joints and Opticians (Exemption from Section 25(1)) Order 2008, S 91/2008 Joints and Opticians (Investigation of Complaints) Regulations, Map. 213A, RG 2 Joints and Opticians (Practice, Conduct, Ethics and Publicity) Regulations, Map. 213A, RG 3 Joints and Opticians (Registration and Practising Certificates) Regulations, Map. 213A, RG 1 Joints and Opticians (Registration and Practising Certificates) Regulations 2008, S 90/2008 Joints and Opticians (Registration and Practising Certificates) Regulations 2008, S 90/2008 Joints and Opticians (Commencement) Notification 2008, S 89/2008 Joints and Opticians (Commencement) Notification 2008, S 89/2008 Thanks in Advance
|