Link to home
Start Free TrialLog in
Avatar of sdesar
sdesar

asked on

How to count 3 keywords entered by the user..?

sub txtAnalyze {
     my $self = shift;
     my $text = $self->{TEXT};  ## Text that contains the keywords

my $key1_splited  = $self->{EXTRAKEY};

my @key1_splited;
my $tmp;
my $var = ref($key1_splited);

  my $size = scalar(@{$key1_splited});
  print "THE the type is $var and size is $size <br>";

     
foreach $tmp (@{$key1_splited}){
  print "Tmp splitted keys are: $tmp <br>"; # netscape, java, browser
   }


I need to find the keywords in the text file and display the count.

How can i do that?
Avatar of ozo
ozo
Flag of United States of America image

foreach $tmp (@{$key1_splited}){
   my $count = () = $text =~ /\b\Q$tmp\E\b/gi;
   print "Tmp splitted keys are: $tmp, count = $count<br>";
}
Avatar of sdesar
sdesar

ASKER

Thanks a million for your response.

The count works but doesn't seem like its counting right.
I added your code.  It seems like it finds the word and count but does not count the entire text document...

Here's the output-

Extra keys are: 3   netscape
Extra keys are: 1   sizes
Extra keys are: 2   skipper

The html document that I am working with is -
http://208.56.56.72/blaT/Access1.html
Avatar of sdesar

ASKER

Awaiting suggestions.. and comments from ozo and other perl gurus ....

Thanks !
Avatar of sdesar

ASKER

Seems like its only counting the first paragraph..
How can I force it to count these words in the entire document.

Thanks
How are you reading the entire document?
Avatar of sdesar

ASKER

The entire document it read from this ..
my $text = $self->{TEXT};  ## Text that contains the keywords

It dump ascii text - based on this-
 my @text = split /\r?\n/, `lynx -dump -width=4000 $url`;

To view the site visit -
http://208.56.56.72/blaT/frame1.html
the
html page to enter is
http://208.56.56.72/blaT/Access1.html 

Let me know if you need more details.


Thanks for all your help.
Avatar of sdesar

ASKER

Hello Ozo,
I would like to know if you have had some time to review this question.
Thanks!
Avatar of sdesar

ASKER

Thanks ozo for all your help.
Your suggestion as descript works wonderful.
But the reason it coesn't count some words is because of a word like "hey there mr.,SKIPPER; hello world"

There's a " ,  " Before the word and also " ; " after and as a result the KEYWORD gets ignored from the count.
Any suggestions on how to modify the script so it counts SKIPPER but ignores the comma and semicolon.


Here's the script you suggested-

foreach $tmp (@{$key1_splited}){
 print "Tmp splitted keys are: $tmp <br>"; # netscape, java, browser
  }

Thanks.
Avatar of sdesar

ASKER

I am deleting this question because ozo helped me with this in another question that i had.

THanks
ASKER CERTIFIED SOLUTION
Avatar of Mindphaser
Mindphaser

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial