Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

RE: RE: Answer: How do I find the Nth occurrence of a pattern?

by eak (Monk)
on Aug 06, 2000 at 19:20 UTC ( #26433=note: print w/replies, xml ) Need Help??


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

Now using grep...speeed!!
#!/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) = @_; ( grep $list->[$_] == $item, 0..$#$list )[--$n] or -1; } print nth_iter(10, 3, \@string);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://26433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2022-01-20 22:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?