title: Proper spreadsheet build with Excel::Writer::XLSX in perl
body: <p>Being a new perl user, it's hard to understand everything with not much experience. </p>
  
  <p>Bellow is a portion of a perl script which is supposed to build a spreadsheet from parsing a text file generated by a custom software . After execution, the xlsx is built by perl, the product group is populated in each row of the designated column, and the product is inserted in the next column. When I have too many products they end up being inserted in the next column, and the next column, and on and on, of the given group. 
  Ideally I would like to have the multiple products inserted in the next row of the same products column.</p>
  
  <p>Currently:</p>
  
  <p>==========================</p>
  
  <p>Group | Product_1 | Prodcut_2   |</p>
  
  <p>===========================</p>
  
  <p>Ideally:</p>
  
  <p>==================</p>
  
  <p>Group | Product1 |</p>
  
  <p>==================</p>
  
  <p>(blank)   | Product2 |</p>
  
  <p>==================</p>
  
  <p>(blank)   | Product3 |</p>
  
  <p>==================</p>
  
  <p>How would this be accomplished?</p>
  
  <p>Below is a snippet of the current code:</p>
  
  <pre><code>    my $product_regex ='^Newly listed product: (.*)$';
      if ($line =~ /$product_regex/) {
              $change = $1;
  
              if ($some_flag == 1) {
                      $some_flag = 0;
                      push(@{ $product_changes{$group}  } , $change);
              }
      }
  
  
  my $format = $workbook-&gt;add_format();
  $format-&gt;set_text_wrap();
  my $worksheet = $workbook-&gt;add_worksheet( 'Sheet1' );
  # Writing 2 column headers
  $worksheet-&gt;write( 0, 0, 'Group' );
  $worksheet-&gt;write( 0, 1, 'Product' );
  my $row;
  $row = 1;
  for my $key (sort keys %product_changes) {
      # To avoid evaluation from Excel, $key must be placed in quotes
      $worksheet-&gt;write($row, 0, $key, $format );
      $worksheet-&gt;write($row, 1, $product_changes{"$key"},$format );
      $row++;
  </code></pre>