> 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
You can do it a couple of ways (there's ALWAYS more than one way to do it
in Perl). Do you want to find the first element that meets the criteria,
or all of them (you might have duplicates).
The most generic way is to use a foreach loop:
foreach $i (@array) {
if($i eq $item_to_match) {
$match = $i;
$found = 1;
last;
}
}
if($found) {
#do stuff
} else {
#do other stuff
}
You can get fancier if you want to find a subset of elements that match
your search criteria:
my @matched = grep { /030/ } @array;
The test inside of the grep block can be as complex as you need it to be.
-- Brett