LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2014, 12:25 PM   #1
laurel
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled
word count in perl


How can I count words in text by using for loop in perl?
 
Old 12-23-2014, 12:51 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
what have you tried and where are you stuck ?
 
Old 12-23-2014, 01:37 PM   #3
laurel
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
I have tried this:

foreach my $str (split){
$count{$str}++;
}

foreach my $str(sort keys %count) {
print Output "$str $count{$str}\n";
}

But I want to write it using for loop

Last edited by laurel; 12-23-2014 at 02:56 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Word - Automatic Selection Word Count? NotAComputerGuy General 8 10-29-2012 05:18 AM
splitting a fil.e word by word. PERL casperdaghost Linux - Newbie 6 11-23-2010 05:45 AM
Need help in word count command grunge_1 Linux - General 4 03-20-2009 04:01 AM
variable length string using GD (word wrap, carriage return, word/character count)? frieza Programming 1 02-14-2009 05:21 PM
word count pantera Programming 2 08-31-2004 07:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration