in reply to seek question
I can't say I've ever run across an if() statement used as such, I assume that it's doing a if ($. == 1) from 1 to 3 implicitly, but I'm unsure.
One thing I do know is that seek does not reset the line number variable $. when positioning back to the beginning of the file, so you have to set it explicitly:
use warnings; use strict; my $f = "/etc/fstab"; open ( my $fh, "<", $f ); while ( <$fh> ) { print "$.: $_"; } print "=" x 78, "\n\n"; print "after 1st while loop\n"; seek( $fh, 0, 0); # reset line num $. = 0; while ( <$fh> ) { print if (1..3); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: seek question
by kcott (Archbishop) on Feb 10, 2017 at 06:42 UTC | |
|
Re^2: seek question
by Marshall (Canon) on Feb 09, 2017 at 21:34 UTC | |
by stevieb (Canon) on Feb 09, 2017 at 21:42 UTC |