monkfan has asked for the wisdom of the Perl Monks concerning the following question:
Most revered monks,
The built-in index function seems to be able to recognize only the first substring given two identical substrings from a string. My code below:
Regards,
Edward
The built-in index function seems to be able to recognize only the first substring given two identical substrings from a string. My code below:
Returns:#!/usr/bin/perl -w use strict; my $str = 'NNNNNATCGNNNNATCG'; my @substr = qw(ATCG ATCG); foreach (@substr) { my $id = index($str,$_); print "$id\n"; }
How can I overcome this problem such that the index function can recognize the second substrings in the correct position? Returning this instead:5 5
5 13
Regards,
Edward
Back to
Seekers of Perl Wisdom