Front page | perl.beginners |
Postings from May 2007
May 19, 2007 22:42
Message ID: email@example.com
I got two arrays of strings.
I am trying to search to see if any of the strings of one array
matches a string of the other array.
Lists to search:
qw/big bad blue ball/, qw/box sand house/
qw/brown black blue/
I should be able to get list #1 but not list #2 because the first list
has "blue" as does the search list.
# Look in
@list1 = qw/big bad blue ball/;
@list2 = qw/box sand house/;
@keywords = qw/brown black blue/;
# Add a ^ and $ so the strings match fully
push @search, qr/^$_$/ for ( @keywords );
$searchRegEx = join '|',@search;
print "1" if ( grep $searchRegEx, @list1 );
print "2" if (grep $searchRegEx, @list2);
Um. Please help?