title: When comparing two files, how do I skip (ignore) blank lines?
body: <p>I'm comparing line against line of two text files, <code>ref.txt</code> (reference) and <code>log.txt</code>. But there may be an arbitrary number of blank lines in either file that I'd like to ignore; how can I accomplish this?</p>
  
  <p><strong>ref.txt</strong></p>
  
  <pre><code>one
  
  two
  
  
  three
  
  
  
  end
  </code></pre>
  
  <p><strong>log.txt</strong></p>
  
  <pre><code>one
  two
  three
  end
  </code></pre>
  
  <p>There would be no incorrect log lines in the output, in other words <code>log.txt</code> matches with <code>ref.txt</code>.</p>
  
  <p>What I like to accomplish in pseudo code:</p>
  
  <pre><code>while (traversing both files at same time) {
      if ($l is blank line || $r is blank line) {
          if ($l is blank line)
              skip to next non-blank line
          if ($r is blank line)
              skip to next non-blank line
      }
      #continue with line by line comparison...
  }
  </code></pre>
  
  <p>My current code:</p>
  
  <pre><code>use strict;
  use warnings;
  
  my $logPath    = ${ARGV [0]};
  my $refLogPath = ${ARGV [1]} my $r;    #ref log line
  my $l;                                 #log line
  
  open INLOG, $logPath    or die $!;
  open INREF, $refLogPath or die $!;
  
  while (defined($l = &lt;INLOG&gt;) and defined($r = &lt;INREF&gt;)) {
      #code for skipping blank lines?
      if ($l ne $r) {
          print $l, "\n";                #Output incorrect line in log file
          $boolRef = 0;                  #false==0
      }
  }
  </code></pre>