in reply to Re^2: How to check if a file has more than one line?
in thread How to check if a file has more than one line?
use strict; use warnings; open my $file, '<', "filename"; my $count_lines; my @array; while (<$file>) { $count_lines++; push @array, qw($_); last if ( $count_lines == 2 ); } my $lines = @array; print $lines; if ( $lines == 1 ) { print "this file only has 1 line"; } else { print "this file has 2 or more lines"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to check if a file has more than one line?
by GrandFather (Saint) on Dec 05, 2014 at 04:40 UTC |