is there a direct way to find out the index of an array element,
like for example
@a=qw(a b c);
how do you get the index of the element b;
i know its 1, but imagine this situation for a large array.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that the ‘answer’ is still 1 when searching for ‘b’ in:
then, use module List::MoreUtils and
firstidx(akafirst_index):The only downside to this is that List::MoreUtils is not (AFAICS) a core module – so it has to be installed from CPAN. At least, the Perl documentation doesn’t document it.