title: Perl script problems
body: <p>The purpose of the script is to process all words from a file and output ALL words that occur the most. So if there are 3 words that each occur 10 times, the program should output all the words.</p>
  
  <p>The script now runs, thanks to some tips I have gotten here. However, it does not handle large text files (i.e. the New Testament). I'm not sure if that is a fault of mine or just a limitation of the code. I am sure there are several other problems with the program, so any help would be greatly appreciated.</p>
  
  <pre><code>#!/usr/bin/perl -w
  require 5.10.0;
  
  print "Your file: " . $ARGV[0] . "\n";
  #Make sure there is only one argument
  if ($#ARGV == 0){
  
      #Make sure the argument is actually a file
      if (-f $ARGV[0]){
  
          %wordHash = ();     #New hash to match words with word counts
          $file=$ARGV[0];     #Stores value of argument
          open(FILE, $file) or die "File not opened correctly.";
  
          #Process through each line of the file
          while (&lt;FILE&gt;){
              chomp;
              #Delimits on any non-alphanumeric
              @words=split(/[^a-zA-Z0-9]/,$_);
              $wordSize = @words;
  
              #Put all words to lowercase, removes case sensitivty
              for($x=0; $x&lt;$wordSize; $x++){
                  $words[$x]=lc($words[$x]);
              }
  
              #Puts each occurence of word into hash
              foreach $word(@words){
                  $wordHash{$word}++;
              }
          }
          close FILE;
  
          #$wordHash{$b} &lt;=&gt; $wordHash{$a};
          $wordList="";
          $max=0;
  
          while (($key, $value) = each(%wordHash)){
              if($value&gt;$max){
                  $max=$value;
              }
              }
  
          while (($key, $value) = each(%wordHash)){
              if($value==$max &amp;&amp; $key ne "s"){
                  $wordList.=" " . $key;
              }
              }       
  
          #Print solution
          print "The following words occur the most (" . $max . " times): " . $wordList . "\n";
      }
      else {
          print "Error. Your argument is not a file.\n";
      }
  }
  else {
      print "Error. Use exactly one argument.\n";
  }
  </code></pre>