more useful options | |
PerlMonks |
Re: Find element in arrayby johngg (Canon) |
on Feb 16, 2020 at 15:28 UTC ( [id://11113027]=note: print w/replies, xml ) | Need Help?? |
Does this do what you want? There is no need to split the sequence into an array as pos will allow you to find where in a string a match has been made. Note that [^ACGT] is a negative character class, i.e. match anything that isn't A, C, G or T. Using capturing parentheses, ( ... ), and matching globally, m{ ... }g or / ... /g will advance along the sequence looking for invalid letters. I am opening a file that is held inside the script just to keep things tidy on my system but the code will work fine with STDIN. The code.
The output.
I hope this is helpful. Please ask further if you need more help. Update: There was a mistake in the code, I should have used a look-ahead assertion as without that pos gives the position after the match, not that of the match itself. Added extended syntax ((?x)) to make the regex clearer. My bad :-( Update 2: I should also have corrected the output, now done. Cheers, JohnGG
In Section
Seekers of Perl Wisdom
|
|