Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: need help in extending the code

by Marshall (Prior)
on Jul 27, 2011 at 21:06 UTC ( #917134=note: print w/ replies, xml ) Need Help??


in reply to need help in extending the code

#!/usr/bin/perl -w use strict; my $x= "it is not probably that it is the end"; my @ngram; my @wds = split(' ',$x); while (@wds>=3) { push @ngram, join(" ",@wds[0..2]); shift @wds; } print join("\n",@ngram),"\n"; __END__ it is not is not probably not probably that probably that it that it is it is the is the end


Comment on Re: need help in extending the code
Download Code
Re^2: need help in extending the code
by sarvan (Sexton) on Jul 28, 2011 at 04:12 UTC
    Hi marshall,

    Thanks for the help. And in the same script which you have provided me few days ago and i also modified and posted yesterday. In that i want the comparison to be case-sensitive which means all words should be compared without case-sensitivesness..

    for eg. If i have the word "finding" in the candidate and "Finding" in reference. The present script dont give the count in reference for that word, since it has capital F.

    So, how can deal with this case-sensitive problem. Any help plz

      I'm not sure what you need. To count the number of occurrences of "finding" in a case insensitive way would require the /i switch for case_insensitive and then the /g switch to keep going globally.

      There is a critter, called the goatse operator, "=()=" that will give the scalar count of the number of matches. You can read about it here: goatse operator. Or just look at the code and play with it..

      !/usr/bin/perl -w use strict; my $x = "Finding fiNding fIndinG finding"; my $count = () = $x =~ /finding/ig; print "$count\n"; #prints 4

      In that i want the comparison to be case-sensitive which means all words should be compared without case-sensitivesness..

      Say that out loud and see if it makes sense to you -- in the same sentence you use "case-sensitive" to mean both case-sensitive and case-insensitive

      So what is your goal?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (14)
As of 2014-09-18 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (123 votes), past polls