Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: count the maximum no.of occurence

by Anonymous Monk
on Jun 30, 2011 at 07:34 UTC ( #912121=note: print w/replies, xml ) Need Help??


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

Hi jwkrahn, Again the output is something like this..

No it isn't. The code from jwkrahn produces the output you wanted. If it does not do that for you, then you are not executing that code.

  • Comment on Re^5: count the maximum no.of occurence

Replies are listed 'Best First'.
Re^6: count the maximum no.of occurence
by sarvan (Sexton) on Jun 30, 2011 at 10:52 UTC
    Hi,

    Sorry if i argued. Actually i did clicked the download but which takes me to plain text page where i can copy the code.

    This is how i have done.. It doesnt work in my windows perl but now i tested in ubuntu perl. its working. The output is exactly as i m expected.

    I think there may be some problem with version. Thanks for the replies..

Re^6: count the maximum no.of occurence
by sarvan (Sexton) on Jun 30, 2011 at 09:24 UTC
    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.

      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.

Re^6: count the maximum no.of occurence
by sarvan (Sexton) on Jun 30, 2011 at 07:44 UTC
    Hi, After execution only i got the output that i showed a while ago.. Also there is an error along with the output shown:
    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 Quantifier follows nothing in regex; marked by <-- HERE in m/(+ <-- HE +RE lways obey the)/ at ngram1.pl line 12.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2023-12-04 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (25 votes). Check out past polls.

    Notices?