title: Perl: Compare Two CSV Files and Print out differences
body: <p>I'm a noob in Perl and I'm having a tough time getting this done. I have two single-columned CSV files, and I'm trying to print the differences to a third file.</p>
  
  <pre><code>File1:
  123
  124
  125
  126
  
  File2:
  123
  124
  127
  
  Expected Output:
  125
  126
  127
  </code></pre>
  
  <p>This is what I've got so far, which isn't working:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  
  my $sheet_1;
  my $sheet_2;
  my $count1 = 0;
  my $count2 = 0;
  
  my $file1 = 'file1.csv';
  my $file2 = 'file2.csv';
  my $file_out = 'output.csv';
  
  open (FILE1, "&lt;$file1")  or die "Couldn't open input file: $!"; 
  open (FILE2, "&lt;$file2")  or die "Couldn't open input file: $!"; 
  
  
  while( &lt;FILE1&gt; ) {
    chomp;
    $count1++;
    #skip header;
    next unless $count1;
    my $row_1;
    @$row_1 = split( /,/, $_ );
    push @$sheet_1, $row_1;
  }
  @$sheet_1 = sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] } @$sheet_1;
  
  while( &lt;FILE2&gt; ) {
    chomp;
    $count2++;
    #skip header;
    next unless $count2;
    my $row_2;
    @$row_2 = split( /,/, $_ );
    push @$sheet_2, $row_2;
  }
  
  @$sheet_2 = sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] } @$sheet_2;
  
  
  OUTER: {
       foreach my $row_1 ( @$sheet_1 ) {
           foreach my $row_2 ( @$sheet_2 ) {
          if (@$row_1[0] eq @$row_2[0]){
          last OUTER
          }
          else{
          print "@$row_1[0]\n";
          }
          }
      }
  }
  
  close FILE1;
  close FILE2;
  </code></pre>