By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,660 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,660 IT Pros & Developers. It's quick & easy.

how to count certain words

P: 10
Hello All!

There is a text I want to process. The name Horch appeares 4 or 5 times. The question is: how can I count the number of appearences with a Perl program?
Thank you for your answer in advance.

Gábor Szepes
Jul 31 '08 #1
Share this Question
Share on Google+
5 Replies


rajiv07
100+
P: 141
Expand|Select|Wrap|Line Numbers
  1. my $val='rajiv gandhi rajiv rajiv';
  2. my $count=$val=~ s/rajiv/rajiv/g;
  3. print $count;
  4.  
try this
Jul 31 '08 #2

P: 10
Hello!

Thanks. It is working.

Gábor
Aug 1 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
Expand|Select|Wrap|Line Numbers
  1. my $val='rajiv gandhi rajiv rajiv';
  2. my $count=$val=~ s/rajiv/rajiv/g;
  3. print $count;
  4.  
try this
Rajiv,

First, Please use code tags around your code that gets posted. You've been around a little while and should really know this.

Second, because this sounds like something that would be asked on homework, I personally would not have given an answer. It is this sites policy not to answer homework outright and we are not a coding service. It would have been more beneficial to the OP if he or she were asked to post the code that they have tried to do their task, rather then to just give them the code. That way, they learn something and they don't get the A+ for your work.

Regards,

Moderator
Aug 1 '08 #4

rajiv07
100+
P: 141
Rajiv,

First, Please use code tags around your code that gets posted. You've been around a little while and should really know this.

Second, because this sounds like something that would be asked on homework, I personally would not have given an answer. It is this sites policy not to answer homework outright and we are not a coding service. It would have been more beneficial to the OP if he or she were asked to post the code that they have tried to do their task, rather then to just give them the code. That way, they learn something and they don't get the A+ for your work.

Regards,

Moderator
numberwhun,

Hereafter I wont repeat such a mistake.

Regards
Rajiv
Aug 2 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
numberwhun,

Hereafter I wont repeat such a mistake.

Regards
Rajiv
'

Thanks! We appreciate that.

Regards,

Jeff
Aug 4 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.