Hi all,
I have a requirement to match a file against a number of possible
strings.
I also need to retain the successfully matching elements, and based on
the match from the primary list, see if a corresponding secondary match
is also in the file.
E.g.. Picture the list below
A B
---------
1 a
2 b
3 c
4 d
5 e
6 f
I need to match any of the first column in the file, and for any matches
in the first row match the corresponding entry for the second column.
So if I match 3 and 5 in the file, I rescan and see if I can match c or
e in the same file.
Here is a snippet of how I am matching anything from column A, and then
rescanning for only corresponding entries from column B.
Is there a more efficient method than what I am doing here?
while(<FILE>)
{
foreach my $string (@strings)
{
if (grep /$string/i, $_)
{
$primary =++$primary;
if (!grep /$string/i,
@matchindex){push(@matchindex, "$string");}
print gmtime()."\"$file\" matched on primary -
$string\n";
}
}
}
close(FILE);
if (@matchindex)
{
# GetSecondaries() Reads array to get 2nd column entries for
primary matches by splitting row on seperators
my @matches = GetSecondaries(@matchindex);
open(FILE, $file);
LOOP: while(<FILE>)
{
foreach my $string (@matches)
{
if (grep /$string/i, $_)
{
$secondarycounter = ++$secondarycounter;
print gmtime()."********\t: Also matched
on secondary - $string\n";
logger("$string,$file"); #
Logs output to a log file
last LOOP;
}
}
}
close(FILE);
**********************************************************************
Private, Confidential and Privileged. This e-mail and any files and attachments
transmitted with it are confidential and/or privileged. They are intended
solely for the use of the intended recipient. The content of this e-mail and
any file or attachment transmitted with it may have been changed or altered
without the consent of the author. If you are not the intended recipient,
please note that any review, dissemination, disclosure, alteration, printing,
circulation or transmission of this e-mail and/or any file or attachment
transmitted with it, is prohibited and may be unlawful. If you have received
this e-mail or any file or attachment transmitted with it in error please
notify Anglo Irish Bank Corporation Limited, Stephen Court, 18/21 St Stephen's
Green, Dublin 2, Ireland, telephone no: +353-1-6162000.
Directors: D O'Connor (Chairman), F Daly, A Dukes, M Keane, D Quilligan.
Registered Office: Stephen Court, 18/21 St Stephen's Green, Dublin 2 Ireland
Registered in Ireland: No 22045
Anglo Irish Bank Corporation Limited is regulated by the Financial Regulator.
Anglo Irish Bank Corporation Limited (trading as Anglo Irish Bank Private
Banking) is regulated by the Financial Regulator. Anglo Irish Assurance Company
Limited is regulated by the Financial Regulator.
**********************************************************************
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs