Perl has a foreach loop that is very apt at doing what you want.

i.e.

#!/usr/local/bin/perl5

$test1 = "030";
@holder = qw(020 040 034 056 030);
foreach (@holder) {
     $test = true if ($_ == $test1);
}

This loop cycles through each element of the array, temporarily housing it 
in the special variable $_  and then compares it to test1.  Of course you 
could have the loop exit when it finds the condition by using last.


At 07:55 PM 5/17/01 +0000, you wrote:
>Hi,
>
>Today is my first day on Perl so please bear with me if this sounds stupid...
>
>How can I find out if an array contains a particular element stored in a 
>certain variable ?
>
>eg variable TEST1 = "030"
>
>array HOLDER = "020 040 034 056 030"
>
>I need to find out if "030" is present in the array HOLDER
>
>Any help on how to do this would be really appreciated.

Peter Cline
Inet Developer
New York Times Digital

Reply via email to