List Info

Thread: RE: Index of element in array?




RE: Index of element in array?
user name
2007-10-22 15:22:18
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: activeperl-bounceslistserv.ActiveState.com
[mailto:activeperl-bounceslistserv.ActiveState.com]
On Behalf Of
Deane.Rothenmaierwalgreens.com
Sent: Monday, October 22, 2007 16:13
To: activeperllistserv.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
ActivePerllistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )