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

In reply to Re: Filter and writing error log file by trippledubs
in thread Filter and writing error log file by newtoperlprog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.