Click to See Complete Forum and Search --> : problem matching elements.


buggy
09-30-2004, 04:41 PM
I have an array of elements, most of which are fine to print to a file. I have a list of words (life,death,ireland,professional,sector) and when one of these words occurs I dont want it to be printed but if one of the words appears as part of a phrase all is fine. I mean 'my professional world' should be allowed.

my array of elements is : myarray;
At the moment I am trying;

foreach $ele (@myarray){

if(grep /life|death|ireland|professional|sector/i,$ele){
#we dont want these
}
else
{
print $ele,"\n";
}
}

The original list (life,death,ireland,professional,sector) is blocked correctly but 'my professional world' is also blocked which I dont want.

I only want to stop exact matches of each word.

Any help would be great.

Jeff Mott
09-30-2004, 07:36 PM
You're going to have to get a bit more specific then as to what constitues an acceptable usage of your bad word list.

Nedals
10-01-2004, 01:53 AM
foreach $ele (@myarray){
if ($ele =~ /^(life|death|ireland|professional|sector)$/i) {
#we dont want these
}
else
{
print $ele,"\n";
}
}

buggy
10-01-2004, 11:22 AM
OK, firstly thanks for your replies:

For all elements in the list I dont want to print exact matches.

(eg: $myarray[10] is 'death'
$myarray[10] is 'life'
$myarray[10] is 'ireland'
.
.
.

are all not printed.

However entries where one of the bad list elements is only part of the entry are printed.

$myarray[11] is 'death by drowning'
$myarray[10] is 'my life'
$myarray[10] is 'sector H'

are printed

For 'ireland' I want to block exact matches like all the other bad list elements but also occurences where 'IE-' is also in the array element.

(eg: 'ireland' is not printed,
'IE-Dublin-Ireland' is also not printed
BUT 'Maxol Ireland' is printed
AND 'Chemist Ireland' is printed)

I need to watch case so I am thinking of putting $ele =~ tr/[A-Z]/[a-z]/;

Nedals
10-01-2004, 12:40 PM
@myarray = ('ireland','IE-Dublin-Ireland','Maxol Ireland','Chemist Ireland');

foreach $ele (@myarray){
if ($ele =~ /^\S*(life|death|ireland|professional|sector)\S*$/i) {
print "DO NOT PRINT: $ele\n";
}
else
{
print "$ele\n";
}
}

I need to watch case so I am thinking of putting....
:confused: The above is case insensitive.