How to find the the indice number of the array that has a given string in it in Perl?

Hi,
I have an array called @data.

In this array, I am looking for $line.

How can I find the the indice number of the array that has $line in it in an efficient way?

Thanks,
TolgarAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
@indice{@data}=(0..$#data);

for $line ( @lines ){
   print $number = $indice{$line};
}
0
 
FishMongerConnect With a Mentor Commented:
use List::MoreUtils qw(indexes first_index);

my @list = (1, 4, 3, 2, 4, 6);

my $first_index = first_index {/4/} @list;
my @all_indexes = indexes {/4/} @list;

print "first index:$first_index\n";
print "all indexes:@all_indexes\n";

Open in new window

0
 
ozoCommented:
Can you clarify what you mean by "has"?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.