title: Text::Csv module in perl, writing data inside a csv
body: <p>In the synopsis of <a href="https://p3rl.org/Text::CSV" rel="nofollow"><code>Text::CSV</code></a> there's this example</p>
  
  <pre><code>my @rows;
  my $csv = Text::CSV-&gt;new ( { binary =&gt; 1 } )  # should set binary attribute.
          or die "Cannot use CSV: ".Text::CSV-&gt;error_diag ();
  
  open my $fh, "&lt;:encoding(utf8)", "test.csv" or die "test.csv: $!";
  
  while ( my $row = $csv-&gt;getline( $fh ) ) {
      $row-&gt;[2] =~ m/pattern/ or next; # 3rd field should match
      push @rows, $row;
  }
  
  $csv-&gt;eof or $csv-&gt;error_diag();
  close $fh;
  
  $csv-&gt;eol ("\r\n");
  
  open $fh, "&gt;:encoding(utf8)", "new.csv" or die "new.csv: $!";
  $csv-&gt;print ($fh, $_) for @rows;
  close $fh or die "new.csv: $!";
  </code></pre>
  
  <p>I see that it pushes some rows on the array <code>@rows</code>, and then the array gets printed line by line inside the output file.</p>
  
  <p>I need to do a similar thing (like checking for a pattern and then save the row to rewrite it on another file later) but I need just one field from each row, and I need to add new fields to the <code>$row</code> that is been pushed. How would I do that?</p>