in reply to Re: Problem in "index" function in recognizing repeating substrings
in thread Problem in "index" function in recognizing repeating substrings

Dear ysth,
Thanks a lot for pointing out the important case that I missed.
With your example above, I will opt for the 'closest' substrings namely:
0 and 2
If the latter
You mean the 'former'? Because, having tested your above code, I think it already gave that answer..
Please correct me if I'm wrong.

Regards,
Edward
  • Comment on Re^2: Problem in "index" function in recognizing repeating substrings
  • Download Code

Replies are listed 'Best First'.
Re^3: Problem in "index" function in recognizing repeating substrings
by saberworks (Curate) on Sep 02, 2005 at 16:05 UTC
    No, his code clearly gives 0 and 6. If you want 0 and 2, try this:
    #!/usr/bin/perl use strict; my $str = 'ATCGATCGAT'; my @sub = qw(ATCG CGAT); my $id = 0; foreach (@sub) { $id = index($str, $_, $id); print "$id\n"; $id++; }