Edward WIJAYA wrote:On Wed, 17 Nov 2004 16:35:58 +0530, Prasanna Kothari <[EMAIL PROTECTED]> wrote:
try using grep function. perldoc -f grep
Yes correct, didn't think of that before.
@exist_elems = grep {/$mystring/} @array_orgn;
0) there is no 'my' in that example, use strict and warnings :) (my @exists_elems ...)
1) what if $mystring is foo and the array elements are foobar, food,bazfoo - it will be true but it doesn't contain your string really ?
2) what is the variable contains malicious code?
This addresses all of those things:
print 'Yes it exixts' if grep /^\Q$mystring\E$/, @myarray;
3) Why use a regexp at all?
print 'Yes it exists' if grep $mystring eq $_, @myarray;
4) Why continue looping through the whole array when a matching element has been found?
for (@myarray) {
print 'Yes it exists' and last if $mystring eq $_;
};-)
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
