in reply to array index
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};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: array index
by monkeybus (Acolyte) on May 20, 2007 at 07:14 UTC | |
by wfsp (Abbot) on May 20, 2007 at 07:28 UTC | |
by bart (Canon) on May 20, 2007 at 08:52 UTC |