From: Tara Calishain <[EMAIL PROTECTED]>
> I know you can compare two variables:
>
> if ($foo eq $otherfoo) {things happen}
>
> What I want to know is if you can do something that compares a
> variable to every element in an array. For example, would something
> like
>
> if ($foo eq @fooarray) {things happen}
>
> work?
>
> I'm trying to say, "If the variable $foo equals any element in the
> array @fooarray things happen."
if (grep {$foo eq $_} @fooarray) {be there light}
The grep{} loops over a list/array, evaluates the condition for each
element and returns a list of elements that were accepted or (in
scalar context) the number of times the condition was true.
If you do this a lot you should consider using a hash. Then you could
write the condition like this:
if (exists $foohash{$foo}) {be there light}
Consult your books about hashes.
Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
--- me
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]