title: Retrieve first row from CSV as headers using Text::CSV
body: <p>I feel like I'm missing something rather obvious, but can't find any answers in the documentation. Still new to OOP with Perl, but I'm using Text::CSV to parse a CSV for later use.  </p>
  
  <p>How would I go about extracting the first row and pushing the values to array @headers?</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>#!/usr/bin/perl
  use warnings;
  use diagnostics;
  use strict;
  use Fcntl ':flock';
  use Text::CSV;
  
  my $csv = Text::CSV-&gt;new({ sep_char =&gt; ',' });
  my $file = "sample.csv";
  my @headers;        # Column names
  
  open(my $data, '&lt;:encoding(utf8)', $file) or die "Could not open '$file' $!\n";
  while (my $line = &lt;$data&gt;) {
    chomp $line;
  
    if ($csv-&gt;parse($line)) {             
      my $r = 0;      # Increment row counter
      my $field_count = $csv-&gt;fields();       # Number of fields in row
  
      # While data exists...
      while (my $fields = $csv-&gt;getline( $data )) {
        # Parse row into columns
        print "Row ".$r.": \n";    
  
        # If row zero, process headers
        if($r==0) {
          # Add value to @columns array
          push(@headers,$fields-&gt;[$c]);
        } else {
          # do stuff with records...
        }         
    }
    $r++
  }           
  close $data;
  </code></pre>
  
  <p>You'd think that there would be a way to reference the existing fields in the first row.                </p>