in reply to If/else within a foreach loop to check strings within an array

Whilst for the very short input in your example choroba's solution is perfectly fine, for real sequences which are typically very large, spliting the sequence to an array of scalars each holding a single char and then processing them one at a time is grossly inefficient. Of both time and memory.

Far more efficient for your stated purpose is to process the sequence as a string:

my $dna_input = $ARGV[0]; print "Non-nucleotide '$1' at posn %d\n", $-[0] while $dna_input =~ m[ +([^acgt])]g;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: If/else within a foreach loop to check strings within an array
  • Download Code

Replies are listed 'Best First'.
Re^2: If/else within a foreach loop to check strings within an array
by LanX (Saint) on Oct 19, 2013 at 22:47 UTC
    > Whilst for the very short input in your example choroba's solution is perfectly fine,

    Read again! No big difference to your approach.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      You're correct. My mistake.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.