in reply to Re^2: Proper usage of rindex function?
in thread Proper usage of rindex function?
See perlrequick.
Your regexp is capturing into $1 just one character, since you are using a character class. It is looking for:
So, ignoring the fact that you have two variable $last_char and $last_mapped_char, it makes sense that you get a result, since you will have captured the last, last occurrence with your regexp, because it's greedy and the first part of it will eat up all the letters except for the last one. It's probably not how you want to code it, though.[ATCG]+ # one or more of any of A,T,C,G # followed by ([ATCG]) # exactly one of A,T,C,G # which is captured into $1 # followed by \.+ # one or more dots # followed by $ # the end of the string
Try running some tests:
perl -Mstrict -wE ' my $str = "ATCGATCG..."; if($str=~/[ATCG]+([ATCG])\.+$/) { my $last_char=$1; say $last_char; my $pos = rindex($str, $last_char); say $pos; } ' G 7
perl -Mstrict -wE ' my $str = "ATCGATCGA..."; if($str=~/[ATCG]+([ATCG])\.+$/) { my $last_char=$1; say $last_char; my $pos = rindex($str, $last_char); say $pos; } ' A 8
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Proper usage of rindex function?
by Anonymous Monk on Dec 29, 2017 at 12:42 UTC | |
by 1nickt (Canon) on Dec 29, 2017 at 12:54 UTC | |
by Anonymous Monk on Dec 29, 2017 at 13:06 UTC | |
by Anonymous Monk on Dec 29, 2017 at 16:35 UTC | |
by Anonymous Monk on Dec 29, 2017 at 21:33 UTC |