in reply to Set Operators
But if you must do this for some reason then as the other replies have said you can use grep. Except that you probably dont want to do that. :-) grep() is slow for this type of job. grep() is intended for finding "all the members of an array that meet a set of criteria", but what you have asked for is "find if there is an element in the array that meets a set of criteria" which is pretty different. A simple (practically) textbook solution is
Where $found will whether the array contains a value (in the case numerically) equivelent with $scalar. A way to do this as an expression (ie in the if you gave as an example) is heremy $found=0; $_==$scalar and ($found=1),last for @array;
Of course you could set it up in a sub or do any number of other things....if (do {my $f=0; $_==$scalar and ($f=1),last for @array; $f}) { }
Remember using a hash in this situation is much smarter than using either this solution or grep()
--- demerphq
my friends call me, usually because I'm late....
|
|---|