How would I skip say line 9 while I'm parsing a text file?
Here's what I got
use strict; use warnings;
open(my $fh, '<', 'file.txt') or die $!;
my $skip = 1;
while (<$fh>){
$_=~ s/\r//;
chomp;
next if ($skip eq 9)
$skip++;
}
Not sure if this works but I'm sure there's a more eloquent of doing it.
You can use $.
:
use strict; use warnings;
open(my $fh, '<', 'file.txt') or die $!;
while (<$fh>){
next if $. == 9;
$_=~ s/\r//;
chomp;
# process line
}
Can also use $fh->input_line_number()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With