1830242 Members
2313 Online
109999 Solutions
New Discussion

Perl Regular Expressions

 
SOLVED
Go to solution
Junior C.
Frequent Advisor

Perl Regular Expressions

Following is snippet of my script.

my @SalesDst = ('www1001',
'qqq001',
);

foreach my $dst (@SalesDst)
{
open(IN, $DST_File) or die "Could not open $DST_File: $!\n";
my @logarray=;
my $lookfor=("$dst");
my @match=grep{/$lookfor/}@logarray;

if (@match)
{
print @match;
}

OUTPUT:
21744329 Jan 10 0:16 www1001
2379202 Jan 9 22:50 qqq001

5810 Feb 17 2006 xyqqq001
I wan't exclude
5810 Feb 17 2006 xyqqq001
from out put.


Appreciate all help.

JC.
4 REPLIES 4
Stuart Browne
Honored Contributor

Re: Perl Regular Expressions

Look at the ^ and $ anchor's.
One long-haired git at your service...
Alexander Chuzhoy
Honored Contributor
Solution

Re: Perl Regular Expressions

There are also word anchors in perl. To make it work \bstring\b
Basically it will include only the string 'string'.
Alexander Chuzhoy
Honored Contributor

Re: Perl Regular Expressions

In particular the line:
my @match=grep{/$lookfor/}@logarray;
should look like this:
my @match=grep{/\b$lookfor\b/}@logarray;


And also please assign points...
Junior C.
Frequent Advisor

Re: Perl Regular Expressions

Thread Close.

Stuart / Alexander,

I appreciate your reply.
Thanks.


Alexander, your following reply work.

my @match=grep{/\b$lookfor\b/}@logarray;

Thanks again.

JC.