in reply to Proper usage of rindex function?
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Proper usage of rindex function?
by Anonymous Monk on Dec 29, 2017 at 12:26 UTC | |
by 1nickt (Canon) on Dec 29, 2017 at 12:36 UTC | |
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 |