Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to look for exact pattern match

by arhuman (Vicar)
on Oct 30, 2001 at 16:04 UTC ( [id://122064]=note: print w/replies, xml ) Need Help??


in reply to How to look for exact pattern match

Is the following code what you're looking for ?
use strict; my @array = qw (bga); my @new_array = qw (bga cbga test); my @tester; print "@array\n"; # #foreach my $temp(@array) { # chomp($temp); # @tester = grep !/^$temp$/ig,@new_array; #} my $temp='('.(join'|',@array).')'; @tester = grep !/^$temp$/ig,@new_array; print "@tester\n";

UPDATE :
Ooops davorg said it faster...
Furthermore if it's case-sensitive 'ne' is better than the regex used in my examples...

UPDATE2 :
Thanks Davorg for catching my error !
Only the last element of array will be taken out of the list,
as the @tester array is completly reconstructed at each step of the loop (only ok with one element ;-)
I've corrected the code with another solution...
But you'd definitly better use davorg's one.

"Only Bad Coders Code Badly In Perl" (OBC2BIP)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://122064]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-23 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found