Question : Find position of an element in array - how?

How can I find out what position a certain item is in an array?

For example:

@fruit = ("apple", "orange", "pears", "grapes");

How could I tell that "pears" is @fruit[2] ?



Many Thanks.

Answer : Find position of an element in array - how?

#sorry, that should have been
($pear) = grep{$fruit[$_] eq "pears"}0..$#fruit;
Random Solutions  
 
programming4us programming4us