in reply to skipping the first line of a file
Skipping the header in a for loop (implied with a statement modifier) is quite flexible as you can skip one, two or many lines with equal facility. It also has the advantage that the scalar receiving the readline only exists within the loop.
my $discard = <$fh> for 1 .. 1; # $discard no longer in scope here.
I hope this is of interest.
Cheers,
JohnGG
Update: Fixed typo.
Update 2: ikegami has pointed out that this code is invalid and explained why so don't do this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: skipping the first line of a file
by ikegami (Patriarch) on Jun 12, 2009 at 21:55 UTC | |
by johngg (Canon) on Jun 12, 2009 at 22:39 UTC | |
by ikegami (Patriarch) on Jun 13, 2009 at 20:11 UTC | |
by johngg (Canon) on Jun 13, 2009 at 22:28 UTC | |
by ww (Archbishop) on Jun 13, 2009 at 03:17 UTC | |
by ikegami (Patriarch) on Jun 13, 2009 at 20:19 UTC | |
|
Re^2: skipping the first line of a file
by citromatik (Curate) on Jun 12, 2009 at 21:45 UTC | |
by johngg (Canon) on Jun 12, 2009 at 22:44 UTC |