Perhaps you could discard any lines where the number of zeros exceeds some threshhold that you choose. This will not check for adjacent non-zero values but may be sufficient for your needs.
use strict; use warnings; open my $csvFH, q{<}, \ <<EOD or die qq{open: <<HEREDOC: $!\n}; JOBINIT,2,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 INSAUTH,5,7107,4,9343,5,7716,1,0,3,254,1,0,8,5655,0,0,0,0,0,0,0,0,0,0 INVPSWD,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 INSAUTH,192,440,192,440,188,450,180,450,189,447,192,440,192,440,188,45 +0,152,438,0,0,36,400,192,440 PWDEXPR,4,222,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 INSAUTH,0,0,0,0,0,0,0,0,0,0,5,7107,4,9343,5,7716,1,0,3,254,1,0,8,5655 UNDFUSER,1,0,1,0,3,4199,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 EOD READFILE: while( <$csvFH> ) { chomp; { no warnings q{numeric}; next READFILE if 15 <= grep $_ == 0, split m{,}; } print qq{$_\n}; } close $csvFH or die qq{close: <<HEREDOC: $!\n};
The output.
INSAUTH,5,7107,4,9343,5,7716,1,0,3,254,1,0,8,5655,0,0,0,0,0,0,0,0,0,0 INSAUTH,192,440,192,440,188,450,180,450,189,447,192,440,192,440,188,45 +0,152,438,0,0,36,400,192,440 INSAUTH,0,0,0,0,0,0,0,0,0,0,5,7107,4,9343,5,7716,1,0,3,254,1,0,8,5655
I hope this is helpful.
Cheers,
JohnGG
Update: Fixed code formatting problem caused by a TAB and changed 0s to zeros for readability.
In reply to Re: Remove array if data inconsistent
by johngg
in thread Remove array if data inconsistent
by meredib
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |