Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

How to count no of words in a text input file?

by vikramkone (Initiate)
on Nov 28, 2007 at 22:30 UTC ( [id://653692]=perlquestion: print w/replies, xml ) Need Help??

vikramkone has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: How to count no of words in a text input file?
by Corion (Patriarch) on Nov 28, 2007 at 22:35 UTC

    You forgot to tell us the email of your teacher. Please update your post and add it.

Using Perlmonks (was: How to count no of words in a text input file?)
by moritz (Cardinal) on Nov 29, 2007 at 08:15 UTC
    Hi vikramkone,

    When you've got a new question, please don't just overwrite the old one with it, because it will render all old answers worthless.

    The people who gave the answers don't like that, and aren't inclined to help you with future problems then.

    Just start a new Seekers of Perl Wisdom for each unrelated question.

Re: How to count no of words in a text input file?
by Cubes (Pilgrim) on Nov 28, 2007 at 23:07 UTC
    Here's another hint: look up the split function.

    The rest of this site might be useful to you as well.

Re: How to count no of words in a text input file?
by roboticus (Chancellor) on Nov 28, 2007 at 23:01 UTC
    vikramkone:

    Here's a hint: HASH

    If you show me what you've got so far, I might be able to offer a better hint...

    ...roboticus

Re: How to count no of words in a text input file?
by moritz (Cardinal) on Nov 28, 2007 at 23:24 UTC
    A partial solution, but better than nothing:
    #!/usr/bin/perl $_=<DATA>; $h{$_}++,$c++,$h{$_}>$n?($n=$h{$_},$m=$_):++$k for map {lc}m/\w+/g; $_="$c words\nmax: '$m' ($n times)$\avg count:".($c/keys %h).$\; print;BEGIN{$\=$/;$/=q//; $,=":"} print@a while@a=each%h; __DATA__ But, in a larger sense, we can not dedicate—we can not consecrate—-we +can not hallow—-this ground. The brave men, living and dead, who stru +ggled here, have consecrated it, far above our poor power to add or d +etract. The world will little note, nor long remember what we say her +e, but it can never forget what they did here. It is for us the livin +g, rather, to be dedicated here to the unfinished work which they who + fought here have thus far so nobly advanced. It is rather for us to +be here dedicated to the great task remaining before us — that from t +hese honored dead we take increased devotion to that cause for which +they gave the last full measure of devotion — that we here highly res +olve that these dead shall not have died in vain — that this nation, +under God, shall have a new birth of freedom — and that government of + the people, by the people, for the people, shall not perish from the + earth

    Update: now with average.

    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How to count no of words in a text input file?
by eric256 (Parson) on Nov 29, 2007 at 00:01 UTC

    Here is the code (encrypted so other students can't steal it ;) ) Now if you can just decrypt it you'll be all set.


    ___________
    Eric Hodges
Re: How to count no of words in a text input file?
by friedo (Prior) on Nov 28, 2007 at 22:50 UTC
    wc -w

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-28 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found