in reply to Find element in array
Instead of matching valid sequences, match invalid characters. Then use $-[0] to find the position of that match. (The @- array is documented in the "perlvar" manual page.)
use strict; use warnings; while (my $sequence = <DATA>) { chomp $sequence; if ($sequence =~ /[^ATCG]/){ warn "Sequence '$sequence' has invalid character after " . $-[ +0]; } else { print "Valid sequence: '$sequence'\n"; } } __DATA__ TAAGAACAATAAGAACAA TAAGAACAATAAUAACAA TAAGAACAATAAGAACAA
You don't need to split the sequence up into individual characters and process each one separately. That's slow.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Find element in array
by LanX (Saint) on Feb 16, 2020 at 13:29 UTC | |
by tobyink (Canon) on Feb 17, 2020 at 13:58 UTC | |
by LanX (Saint) on Feb 17, 2020 at 14:42 UTC | |
by Sofie (Acolyte) on Feb 16, 2020 at 14:56 UTC | |
by LanX (Saint) on Feb 16, 2020 at 18:01 UTC | |
Re^2: Find element in array
by Sofie (Acolyte) on Feb 16, 2020 at 13:22 UTC |
In Section
Seekers of Perl Wisdom