title: Perl Loop Output to Excel Spreadsheet
body: <p>I have a Perl script, the relevant bits of which are posted below.</p>
  
  <pre><code># Pull values from cells
          ROW:
          for my $row ( $row_min + 1 .. $row_max ) {
              my $target_cell   = $worksheet-&gt;get_cell( $row, $target_col);
              my $response_cell = $worksheet-&gt;get_cell( $row, $response_col);
  
              if ( defined $target_cell &amp;&amp; defined $response_cell ) {
                  my $target   = $target_cell-&gt;value();
                  my $response = $response_cell-&gt;value();
  
  # Determine relatedness
                  my $value      = $lesk-&gt;getRelatedness($target, $response);
  
  # Copy output to new Excel spreadhseet, 'data.xls'
                  my $workbook1  = Spreadsheet::WriteExcel-&gt;new('data.xls'); 
                  my $worksheet1 = $workbook1-&gt;add_worksheet();
                  $worksheet1-&gt;set_column(0, 3, 18);
                  my $row = 0;
  
                  foreach ($target) {
                  $row++;
                  $worksheet1-&gt;write( $row, 0, "Target      = $target\n");
                  $worksheet1-&gt;write( $row, 1, "Response    = $response\n");
                  $worksheet1-&gt;write( $row, 2, "Relatedness = $value\n");
                  }
              }
          }
  </code></pre>
  
  <p>This script uses the Perl modules ParseExcel and WriteExcel. The input data spreadsheet is a list of words under two columns, one labelled 'Target' and the other labelled 'Response.' The script takes each target word and each response word and computes a value of relatedness between them (that's what the</p>
  
  <pre><code>$lesk-&gt;getRelatedness
  </code></pre>
  
  <p>section of code is doing. It is calling a perl module called WordNet::Similarity that computes a measure of relatedness between words).</p>
  
  <p>All of this works perfectly fine. The problem is I am trying to write the output (the measure of similarity, or $value in this script) into a new Excel file. No matter what I do with the code, the only output it will give me is the relatedness between the LAST target and response words. It ignores all of the rest. </p>
  
  <p>However, this only occurs when I am trying to write to an Excel file. If I use the 'print' function instead, I can see all of the outputs in the command window. I can always just copy and paste this into Excel, but it would be much easier if I could automate this. Any idea what the problem is? </p>