in reply to Searching mixed array?
Your code as posted can't run because you're using some kind of fancy quotes that Perl does not support:
&find (‘Q', @fsg)
If you used the warnings pragma, Perl would have told you that you're using the wrong operator for string comparisons. See perlop about eq and == and the difference between the two.
Also, if you plan on doing (much) more than one search, using a hash is likely faster:
sub find { my ($needle,@hay) = @_; my $position = 1; my %haystack = map { $_ => $position++ } @hay; return $haystack{ $needle } };
If you look at List::Utils, there is the first subroutine, that also does what your find() subroutine does.
|
|---|