my $search = 'foo'; my ($where) = grep { $question[$_] eq $search } 0 .. $#question;
If you have to do this very often with the same array, it might be better to build a lookup hash. Hash lookup is very fast.
# once: my %lookup; @lookup{@question} = ( 0 .. $#question ); # many times: my $search = 'boo'; $where = $lookup{$search};
In reply to Re: array index
by bart
in thread array index
by monkeybus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |