Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: search one instance

by AnomalousMonk (Archbishop)
on Nov 03, 2010 at 19:38 UTC ( [id://869297]=note: print w/replies, xml ) Need Help??


in reply to search one instance

I don't quite understand how we get from toniax's OP to finding all starting positions of the substring, but here's another way:

>perl -wMstrict -le "my $str = qq{foo data } x 5; print $str; ;; print qq{start of 'data' at $-[1]} while $str =~ m{ (data) }xmsg; " foo data foo data foo data foo data foo data start of 'data' at 4 start of 'data' at 13 start of 'data' at 22 start of 'data' at 31 start of 'data' at 40

See @- (and its cousin @+) in perlvar.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found