in reply to Remove array if data inconsistent

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.

Replies are listed 'Best First'.
Re^2: Remove array if data inconsistent
by meredib (Acolyte) on Apr 22, 2009 at 16:16 UTC
    I've never used grep before and it seems to have been what I was looking for all along. I changed your script a little but this is what did. I added an option when I run the script to be $occurance because it's not going to be the same number every time. Thanks a ton for everyones help.
    open IN, '<'.$inFlNm or die "Unable to open >$inFlNm< : $!\n"; READFILE: while( <IN> ) { chomp; next READFILE if $occurance > grep $_ != 0, split m{,}; print OUT qq{$_\n}; } close IN;