in reply to How do I skip reading files further with missing data?
One way is to count the number of consecutive lines that start with a +- or += (just in case for some reason you have normal lines that start with a +. Hopefully legit lines won't start with += or +-. If they do, you'll have to lengthen the regex). If you get more than one, the file is deemed empty and we skip it. Note I skip the lines that have the separators and don't print them.
use warnings; use strict; my @files = qw(a.txt b.txt); for my $file (@files){ open my $fh, '<', $file or die $!; my $sep = 0; print "working on file $file\n"; while (<$fh>){ if (/^\+[-=]/){ $sep++; if ($sep > 1){ print "skipping $file\n"; last; } next; } $sep--; chomp; print "$_\n"; } }
file a.txt:
+=======+=======+============+============+============+ +-------+-------+------------+------------+------------+
file b.txt:
+=======+=======+============+============+============+ line 1 line 2 +-------+-------+------------+------------+------------+
output:
working on file a.txt skipping a.txt working on file b.txt line 1 line 2
|
|---|