in reply to comparing element in arrays

Something like this should work
foreach $element (@a) { foreach $number (@b) { if ($element =~ /\D$number\D/) { push (@c, $element); } } }
EDIT:added \D around the variable in the REGEX after smoss's response. That should take care of the extra elements your were getting. The way it was before it would pick out 96 in the string if one of the numbers was either 9 or 6, adding the non number boundary should force it to match numbers exactly. It works on my tests. If it still doesn't work for you give me your sample data and I'll see if I can recreate the problem.

John

Replies are listed 'Best First'.
Re: Re: comparing element in arrays
by smoss (Acolyte) on May 20, 2002 at 08:54 UTC
    John, Thanks for the response, this doesn't seem to work, it pushes the $element into the array @c regardless of whether the $element contains the $number or not.
Re: Re: comparing element in arrays
by smoss (Acolyte) on May 20, 2002 at 12:04 UTC
    Thanks John, That did the trick.