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

Re: Find most frequently used word in text file.

by Bloodnok (Vicar)
on Dec 20, 2013 at 09:18 UTC ( #1067937=note: print w/ replies, xml ) Need Help??


in reply to Find most frequently used word in text file.

In addition to the bug pointed out by toolic, I believe that there is a further bug in as much as it [your code] will merely result in a frequency report for the first line, not the whole file as you expect - the line my @lines  = <FILE>; won't slurp in the whole file, it'll merely result in only the first line i.e. all text up to the first end of line char, being read in, you need to undef the line delimiter as in Laurent_R's code i.e. undef $/;.

HTH ,

A user level that continues to overstate my experience :-))


Comment on Re: Find most frequently used word in text file.
Select or Download Code
Re^2: Find most frequently used word in text file.
by hdb (Prior) on Dec 20, 2013 at 09:29 UTC

    This is not correct. From perlop under I/O operators:

    If a <FILEHANDLE> is used in a context that is looking for a list, a list comprising all input lines is returned, one line per list element.
      Aha, TFT hdb - good spot - it's early in the morning (for me) and my contexts are somewhat confused :-(

      My comment would be applicable if the OP was trying to slurp a file into a scalar, which they aren't. I'm not at all sure i.e. can't remember, if I've yet attempted to slurp a file into a list.

      A user level that continues to overstate my experience :-))
        Yes, I used undef $/; because I wanted to slurp the file into a scalar variable (making the subsequent processing slightly simpler). But it would not be necessary to undef $/ in a list context.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067937]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-12-27 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls