davidinottawa has asked for the wisdom of the Perl Monks concerning the following question:
I can't see my error here Monks!!!
I just need to grep where data from the pattern file exists in the input file.
input.file looks like this :
David@domain.com|David@domain.com|J|ABBASS, DAVID JOHN|
Cory@domain.com|Cory@domain.com|E|ABBOTT, CORY J|
Tania@domain.com|Tania@domain.com|F|ABBOTT, TANIA LEE|
Geoffrey@domain.com|Geoffrey@domain.com|N|ABBOTT, GEOFFREY BRYAN|
pattern.file looks like this :
Randall@domain.com
David@domain.com
Rob@domain.com
Tania@domain.com
Script should tell me that Tania@ and David@ exist :
sub main { my $filename = "input.file"; open (my $valuesFile, '<', 'pattern.file') or die "Failed: $!\n"; while (<$valuesFile>) { push (@lines, $_); } open(INPUT, $filename) or die "Cannot open $filename"; while (<INPUT>) { ($userName,$emailAddress,$division,$fullName) = split(/\|/, $_); while (@lines) { my $pattern = pop @lines; $pattern=~s/\n//g; #print "pattern: ".$pattern."address: ".$emailAddress."\n"; if ($emailAddress =~ /$pattern/) { print $pattern . " exists in " . $emailAddress."\n"; } else { print $pattern . " no match " . $emailAddress."\n"; last; } } } close(INPUT); close $valuesFile; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Look for pattern in file. ????
by Corion (Patriarch) on Jan 19, 2016 at 17:00 UTC | |
|
Re: Look for pattern in file. ????
by ikegami (Patriarch) on Jan 19, 2016 at 17:07 UTC | |
by ikegami (Patriarch) on Jan 19, 2016 at 17:16 UTC | |
|
Re: Look for pattern in file. ????
by stevieb (Canon) on Jan 19, 2016 at 16:59 UTC | |
|
Re: Look for pattern in file. ????
by kcott (Archbishop) on Jan 19, 2016 at 21:40 UTC | |
|
Re: Look for pattern in file. ????
by davidinottawa (Initiate) on Jan 19, 2016 at 17:59 UTC |