use List::MoreUtils qw( first_index ); my $i = first_index { $_ eq 'banana' } @list; HOWEVER, you should consider whether you really want to use indexes into lists. In general it is preferred just to iterate over items in a list directly. (See "Perl Best Practices" book from O'Reilly) P.S. Please send only PLAIN TEXT email to mailing lists.
- - Martin ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Monday, October 22, 2007 16:13 To: activeperl@listserv.ActiveState.com Subject: Index of element in array? Gurus, I'm unable to find this in the Camel, Panther, or Billygoat books, so I'll ask you... Is there a Perl function that returns the index of a given element in an array? For example: my @list = q( apple banana pear grapefruit); _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs