in reply to How to look for exact pattern match
grep doesn't do what you think it does. For a start you're assigning the return value to a scalar, but it returns a list.
I think that what you want is something like this:
my @in = qw(bga cbga test); my @out; my @test = qw(bga); foreach my $test (@test) { push @out, grep { /$test/ } @in; }
But I'm slightly worried by your phrase "exact pattern match". Perhaps what you really want is:
--my @in = qw(bga cbga test); my @out; my @test = qw(bga); foreach my $test (@test) { push @out, grep { $_ eq $test } @in; }
"The first rule of Perl club is you don't talk about Perl club."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to look for exact pattern match
by juo (Curate) on Oct 30, 2001 at 15:47 UTC | |
by davorg (Chancellor) on Oct 30, 2001 at 16:00 UTC | |
by clintp (Curate) on Oct 30, 2001 at 18:03 UTC | |
by Fletch (Bishop) on Oct 30, 2001 at 16:56 UTC |