in reply to Re: Determing the indice of an array
in thread Determing the indice of an array
Better for the most general case would be to make a lookup hash keyed by the values of the array, with each value of the hash being a reference to an array to which you push the indices from the original array. That way, when you key the hash with an array value, you get every location in the array where that value occurred.my @a = ('a'..'d','a'..'d'); my %a; @a{\(@a)} = 0..$#a; my $x = 'b'; print "$x has an index of $a{\$x}\n"; b has an index of
|
|---|