title: Perl Script to Count Words/Lines
body: <p>I'm learning PERL for the first time and I am attempting to replicate exactly the simple Perl script on page four of this <a href="http://heather.cs.ucdavis.edu/~matloff/Perl/PerlIntro.pdf" rel="nofollow">document</a>: </p>
  
  <p>This is my code:</p>
  
  <pre><code># example.pl, introductory example
  
  # comments begin with the sharp sign
  
  # open the file whose name is given in the first argument on the command 
  # line, assigning to a file handle INFILE (it is customary to choose
  # all-caps names for file handles in Perl); file handles do not have any
  # prefixing punctuation
  open(INFILE,$ARGV[0]);
  
  # names of scalar variables must begin with $
  $line_count - 0;
  $word_count - 0;
  
  # &lt;&gt; construct means read one line; undefined response signals EOF
  while ($line - &lt;INFILE&gt;) {
      $line_count++;
      # break $line into an array of tokens separated by " ", using split()
      # (array names must begin with @)
      @words_on_this_line - split(" ",$line);
  
      # scalar() gives the length of an array
      $word_count += scalar(@words_on_this_line);
  }
  
  print "the file contains ", $line_count, "lines and ", $word_count, " words\n";
  </code></pre>
  
  <p>and this is my text file:</p>
  
  <pre><code>This is a test file for the example code.
  The code is written in Perl.
  It counts the amount of lines 
  and the amount of words.
  This is the end of the text file that will
  be run
  on the example
  code.
  </code></pre>
  
  <p>I'm not getting the right output and I'm not sure why. My output is:</p>
  
  <pre><code>C:\Users\KP\Desktop\test&gt;perl example.pl test.txt
  the file contains lines and  words
  </code></pre>