CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
pattern match is not working globally

 



arokiamary
New User

Sep 8, 2011, 3:52 AM

Post #1 of 2 (3747 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


BillKSmith
Veteran

Sep 10, 2011, 10:19 AM

Post #2 of 2 (3685 views)
Re: [arokiamary] pattern match is not working globally [In reply to] Can't Post

I am not sure that I understand your question. I think that you believe that your script works correctly on the posted data files. You want to generalize the script to process all files with names matching the pattern LEAP_?.txt. Search the directory for this pattern with glob (refer: perldoc -f glob)
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives