SPUG: IndexOf in Perl?

Brian Wisti brianwisti at yahoo.com
Sat Jan 28 15:16:50 PST 2006


--- Tanwir Habib <tanwirh at hotmail.com> wrote:

> Hi,
> 
> I've recently switched from .NET to Perl for my needs in  
> bioinformatics work.
> 
> Is there a way in Perl to search an array with its value to get its  
> index? like java does with "IndexOf".
> 

You might try the List::Util module. It's core in 5.8.

  use List::Util qw(first);
  ...
  my $index = first { $_ == $test_value } @array;

Kind Regards,

Brian Wisti
http://coolnamehere.com/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the spug-list mailing list