http://www.perlmonks.org?node_id=26406


in reply to Re: How do I find the Nth occurrence of a pattern?
in thread How do I find the Nth occurrence of a pattern?

I have to correct my code. I passed in a reference and never used it :(.
#!/usr/bin/perl -w my @string = (34, 56, 78, 90, 98, 76, 54, 32, 10, 12, 13, 16, 19, 20, +10, 56); sub nth_iter{ my ($item, $n, $list) = @_; ( map { $list->[$_] == $item ? $_ : (); } 0..$#$list )[--$n] or -1 +; } print nth_iter(78, 1, \@string);