chiru has asked for the wisdom of the Perl Monks concerning the following question:
Hi!, I'm trying to create a script which will ask user for file and checks if it has at least 5 line, if it does than print first and last line. I'm getting following errors Use of uninitialized value $lines in concatenation (.) or string at c:\test\perl\test.pl line 9, <FILE> line 6. Use of uninitialized value $lines in numeric lt (<) at c:\test\perl\test.pl line 14. I will really appreciate your help. You may enlight me if there is different way to do it. Thanks, chiru
use warnings; use strict; print "please enter name of file: "; chomp($ARGV=<>); open (FILE, $ARGV) or die "Can't open '$ARGV': $!"; my $lines++ while(<FILE>); print "\$lines: $lines"; my $last; my $first = <FILE>; while (<FILE>) { $last = $_ } close FILE; if($lines<5){ print "file must have more than 5 lines"; } else{ print "\$first: $first"; print "\$last: $last"; }
|
|---|