in reply to Re^4: Proper usage of rindex function?
in thread Proper usage of rindex function?

If that is your spec, then you should use the special array @- to report the position of the match. You don't need rindex for this (although it is possible that using rindex would be faster, even with the additional step of comparing positions, especially with a long string):

perl -Mstrict -wE ' my $str = "ATCGATCGA..."; if ( $str =~ /([ATCG])\./ ) { say "$1 at $-[1]"; } '
Output:
A at 8
See Variables related to regular expressions in perlvar.

Hope this helps!

update: simplified the re


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^6: Proper usage of rindex function?
by Anonymous Monk on Dec 29, 2017 at 13:06 UTC
    Great! Thank you very much!