I'm grabbing a few columns from a tab delineated file in Perl. The first line of the file is completely different from the other lines, so I'd like to skip that line as fast and efficiently as possible.
This is what I have so far.
my $firstLine = 1;
while (<INFILE>){
if($firstLine){
$firstLine = 0;
}
else{
my @columns = split (/\t+/);
print OUTFILE "$columns[0]\t\t$columns[1]\t$columns[2]\t$columns[3]\t$columns[11]\t$columns[12]\t$columns[15]\t$columns[20]\t$columns[21]\n";
}
}
Is there a better way to do this, perhaps without $firstLine? OR is there a way to start reading INFILE from line 2 directly?
Thanks in advance!
You can just assign it a dummy variable for the 1st time:
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '<','a.txt' or die $!;
my $dummy=<$fh>; #First line is read here
while(<$fh>){
print ;
}
close($fh);
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