Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Alternate approach (with a little error checking, which I hope is so basic and transparent as to need no explanation):

You might want to upend your thought process. Simply warn about any elements of your data that have "G" or "T" (and, as you'll see in the code below, any non-conforming data -- letters other'n ACTG; too many or few letters, etc.) and then next past them without saving. Save the desired elements (the digits) to your @positions array, only after substituting away any combinations of "A" and "C" and -- when you've processed all the data, spit out the positions that satisfy your criteria:

#!/usr/bin/perl use 5.014; # 991184 my @positions; my @data = ('1 ACAC', '2 AGAC', '3 AGTC', '4 ACCA', '5 DUMMY', '6 ACAATG', '7 CAAC', '8 acaacc', '9 aca ', ); for my $data(@data) { if ( $data =~ /[GT]/ || $data =~ /[^[ACTG]{4}$/) { say "Data ERROR or contains G or T ( $data )"; next; } elsif ( $data =~ /^\d+ [AC]{4}$/i ) { # too many; too few? cove +red here $data =~ s/ [AC]{4}//i; chomp $data; push @positions, $data; } else { say "Problem with data? $data"; } } print "\n Good data at positions: "; for my $position (@positions) { print "$position "; # depending on size of valid position +s, you may } # want to stack them vertically -- # simply replace the 'print' with 'sa +y' say "\n Done";

Output:

C:\ 991184.pl Data ERROR or contains G or T ( 2 AGAC ) Data ERROR or contains G or T ( 3 AGTC ) Data ERROR or contains G or T ( 5 DUMMY ) Data ERROR or contains G or T ( 6 ACAATG ) Data ERROR or contains G or T ( 8 acaacc ) Data ERROR or contains G or T ( 9 aca ) Good data at positions: 1 4 7 Done

Done in babytalk, to some extent, to ensure clarity. Compare OP's questions about the Monks' responses, above.


In reply to Re: filtering an array by ww
in thread filtering an array by prbndr

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (13)
    As of 2014-07-11 06:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (220 votes), past polls