in reply to Get Position of Element in an array
or create lookup table:my ($pos) = grep $input[$_] eq $val, 0 .. $#input;
my ($first, $last) = ({}, {}); @$first{reverse @input} = reverse 0 .. $#input; @$last{@input} = 0 .. $#input; my $val = 'b'; print "Last index : ", $last->{$val}; print "First index : ", $first->{$val};
|
|---|