Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: compute the occurrence of words

by Utilitarian (Vicar)
on Feb 13, 2013 at 13:34 UTC ( #1018538=note: print w/replies, xml ) Need Help??


in reply to compute the occurrence of words

Please explain what the line $data=<FH> does and why it is there?

Secondly, why would you want to enumerate occurrences of unique things in any other way than as a hash?

You're new to Perl and so it seems an odd data type, but once you get used to using them hashes are a phenomenally useful tool.

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^2: compute the occurrence of words
by vinoth.ree (Monsignor) on Feb 13, 2013 at 13:57 UTC

    Hi Utilitarian yes I agree that hash is the best way to find the unique things, but BigGer is not trying to find the unique words, he tried in his code to counts the occurrence of each word.

      Perhaps I was unclear, one of the things you have to do in order to count the number of occurrences of each word in a given text is to create a list of the unique words present, the other thing you have to do is associate a count with each of these words.

      If you can think of a data structure more suited to this purpose than an associative array or hash, I'd be very interested.

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018538]
help
Chatterbox?
[Corion]: thezip: If you want to confuse your users, use system(1, "that\\command" );, which will make Perl launch it in the background
[Corion]: That will keep the console window open even though the user can't type into it anymore
[thezip]: So I have a script that generates a log file. After script completion, I want tohave VIM open this logfile.
[thezip]: i don't get the command line "back" until I close VIM. No what I want to happen...
[thezip]: I currently don't have access to CYGWIN, else I'd just do a tail -f on the logfile.
[Corion]: thezip: If you want to open vim and can live with opening a second console window, use start "The results" vim.exe c:\path\to\logfile .log

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2017-03-27 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (321 votes). Check out past polls.