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?
#!/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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Answer: How do I find the Nth occurrence of a pattern?
by eak (Monk) on Aug 06, 2000 at 19:20 UTC |