in reply to Filter and writing error log file

This uses a hash to list each criteria test. Per each line of the file, the third column must pass each test for the code to reach the bottom portion. One test, that each input must be 19 characters long, is inline in the test_criteria hash. The other test, must contain other than atgc characters has been separated into its own subroutine.
#!/usr/bin/env perl use strict; use warnings; sub not_only_atgc { my $sequence = shift; if ( $sequence =~ /[^atgc]/i ) { return 1; } return 0; } my %test_criteria = ( "Must not be 19 characters long" => sub { return 1 if (length($_[0]) != 19); }, "Must contain other than atgc" => \&not_only_atgc, ); my $lineno = 0; # Read one line at a time open( my $fh, "data.txt" ) or die "$!"; LINE: while ( my $line = <$fh> ) { $lineno++; my @words = split /\s+/, $line; print "Processing line $lineno interested in $words[2]\n"; TEST: for my $criteria_check ( keys %test_criteria ) { if ( $test_criteria{$criteria_check}->( $words[2] ) ) { # Test + returned 1 } else { print "Fail: $criteria_check\n\n"; next LINE; } } ## All checks have passed after this line ## print "$words[2] passes all criteria\n\n"; }
Updated -- OUTPUT
Processing line 1 interested in caggctcaggacttagcaa Fail: Must contain other than atgc Processing line 2 interested in cttagcaagaagttatgaaa Fail: Must contain other than atgc Processing line 3 interested in ggcycaggacttagcaaga Fail: Must not be 19 characters long Processing line 4 interested in caggacttagcaaoooaagtt caggacttagcaaoooaagtt passes all criteria