in reply to Delete the line
Ok, so you have the individual records in the @data array.
You now need to split the records and check that any of the values in the resultant array with an index > 2 are not equal to zero. If there are print the line.
something like the following is what you are looking for.
use strict; # These two lines use warnings;# will save you grief open (my $data_file, "<", 'test.tsv'); # better to use 3 argument ver +sion of open and to have a lexical filehandle my @data = <$data_file>; # scope your variables close( $data_file); # It's only polite to close up after yourself print $data[0]; # headers for my $line (@data[1..$#data]){ # More perlish not to use indices dir +ectly my @line = split(/\t/, $line); # split the values into an array print $line if (check_for_zero(@line)); # Use a routine to evaluate + the elements } sub check_for_zero{ # declare routine my @line = @_; # get the array we're called with for my $field (@line[2..$#line]){ # again more perlish return 1 if $field != 0; # We have a non-zero value } return 0; #if we got here we never met a non-zero value }
|
|---|