in reply to Re^2: Read and skip a line
in thread Read and skip a line
Your logic is incorrect - here is a version using a "for loop" that you seem to want - , but coded in a more idomatic manner:
There is a small,subtle potential problem inherent in the code above - not corrected in order to maintain simplicity : the $line read in may be empty at EOF.use strict; use warnings; my $filename = shift; open my $file, "<", Filename or die "Cannot open $filename: $!"; chomp (my $lastrecord = <$file>); # Reads in the first record for (my $rec = 1; $rec <= $lastrecord and not eof($file); $rec++) { chomp(my $line = <$file>); print "Line $rec: $line\n"; };
UPDATE:Please do not delete code/comments after posting them - it makes responses like mine look out of context. It also prevents others from learning because context disappears.
All great truths begin as blasphemies.
― George Bernard Shaw, writer, Nobel laureate (1856-1950)
|
|---|