Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

to find string

by harshmane (Initiate)
on Jun 21, 2011 at 05:39 UTC ( [id://910681]=perlquestion: print w/replies, xml ) Need Help??

harshmane has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: to find string
by Ratazong (Monsignor) on Jun 21, 2011 at 05:56 UTC
    What have you tried? Are you aware of index? That should find your substring. And by providing an offset in combination with a loop, counting the number of occurences should be not too difficult ...
Re: to find string
by ikegami (Patriarch) on Jun 21, 2011 at 06:28 UTC

    How many "abab" are "abababab"?

    2:

    # abababab # ---- # ---- my $count = 0; ++$count while $string =~ /\Q$substr/g;

    3:

    # abababab # ---- # ---- # ---- local our $count = 0; $string =~ /\Q$substr\E(?{ ++$count })(?!)/;
Re: to find string
by toolic (Bishop) on Jun 21, 2011 at 13:04 UTC
Re: to find string
by GrandFather (Saint) on Jun 21, 2011 at 05:57 UTC

    Show us what you tried.

    True laziness is hard work
Re: to find string
by Anonymous Monk on Jun 21, 2011 at 06:01 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found