Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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";


C:\ 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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    [marto]: nice
    [choroba]: New blogpost after a long pause!
    marto needs to think of a joke where the punchline is "why the long paws?"

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (9)
    As of 2018-03-20 16:24 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (254 votes). Check out past polls.