in reply to getting error "Use of uninitialized value $lines in concatenation (.) or string at line 6

As suggested above, here is a slightly modified version of your script with addition of just 2 lines.
use warnings; use strict; print "please enter name of file: "; chomp($ARGV=<>); open (FILE, $ARGV) or die "Can't open '$ARGV': $!"; my $lines; $lines++ while(<FILE>); print "\$lines: $lines"; my $last; seek FILE,0,0; 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"; }
  • Comment on Re: getting error "Use of uninitialized value $lines in concatenation (.) or string at line 6
  • Download Code

Replies are listed 'Best First'.
Re^2: getting error "Use of uninitialized value $lines in concatenation (.) or string at line 6
by chiru (Initiate) on Jul 03, 2014 at 05:32 UTC

    Thanks for your effort. I will use $file instead of $ARGV like Athanasius suggested.