Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^6: count the maximum no.of occurence

by sarvan (Sexton)
on Jun 30, 2011 at 09:24 UTC ( [id://912130]=note: print w/replies, xml ) Need Help??


in reply to Re^5: count the maximum no.of occurence
in thread count the maximum no.of occurence

This is what the code suggested:
use warnings; use strict; my $str1 = q/It is a guide to action which ensures that the military a +lways obey the commands of the party./; my $str2 = q/It is a guide to action that ensures that the military wi +ll forever heed Party commands is a guide./; my $n = 0; while ( $str1 =~ /(?=(\S+\s+\S+\s+\S+))/g ) { my $t1 = $1; while ( $str2 =~ /($t1)/g ) { print "$1\n"; $n++; } } print "No of matching is : $n\n";
And here is the output for that:
It is a t is a is a guide is a guide s a guide s a guide a guide to guide to action uide to action ide to action de to action e to action ensures that the nsures that the sures that the ures that the res that the es that the s that the that the military hat the military at the military t the military
I have downloaded the code properly.

Replies are listed 'Best First'.
Re^7: count the maximum no.of occurence
by Anonymous Monk on Jun 30, 2011 at 09:55 UTC

    This is what the code suggested: ...

    I have downloaded the code properly.

    Dear saravan,

    You did not download the code properly. Like I already told you in Re^7: count the maximum no.of occurence, use the download code link to download the code

    And here is the output for that:

    Simply repeating what you already said is annoying, esp when other parts of what you are saying are obviously wrong.

    Which perl are you using? I get the correct output using v5.12.2

    perldeltas says

    A pattern containing a + inside a lookahead would sometimes cause an incorrect match failure in a global match (e.g., /(?=(\S+))/g)

    #68564: /g failure with zero-width patterns

      Cut & paste is not the same as download. The "+" signs in your sample data exist because you didn't use the download link. Instead you used cut & paste. That would be fine, except that perlmonks wraps long code lines (to prevent lines from uglificating the page). When it does so, it includes a '+' at the beginning of wrapped lines to let you know about it.

      If you use the download link, you'll get a nice plain text page that you can save, and it will be the correct code.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-03-29 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found