Hi, what makes you think that you can pass a list of substrings to rindex?
If the substring is not found, index returns -1.
Your code is trying to match the entire substring. You should check each character individually.
Output:perl -Mstrict -wE ' my $str = "GAGAACATTAGTGGGTGCAGCGCACAAGCATGGCACATGTATACGTATGTAA"; say sprintf q{%s is last found at pos %s}, $_, rindex( $str, $_ ) for +qw/A C G T/; '
A is last found at pos 51 C is last found at pos 43 G is last found at pos 48 T is last found at pos 49
Also, always use strict; in your code: it will make Perl tell you about mistakes you've made:
Output:perl -Mstrict -wE ' my $str = "GAGAACATTAGTGGGTGCAGCGCACAAGCATGGCACATGTATACGTATGTAA"; say rindex( $str, [ATCG] ) '
Bareword "ATCG" not allowed while "strict subs" in use at -e line 3. Execution of -e aborted due to compilation errors.
Hope this helps!
In reply to Re: Proper usage of rindex function?
by 1nickt
in thread Proper usage of rindex function?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |