in reply to Re^2: Recovering Substrings to String with Gap
in thread Recovering Substrings to String with Gap
but if the substrings are sorted by their position on the original string, it's easy to solve, just make $after=$pos+1 or:
and if they are not sorted, well, then you can use some hash to remember the last $pos for a given $sbstr and start searching after that...my $pos=0; foreach my $sbstr ( @$array ) { $pos = index $str, $sbstr, $pos; substr ($nstring, $pos, length ($sbstr)) = $sbstr; $pos++ }
my %after; foreach my $sbstr ( @$array ) { my $pos = index $str, $sbstr, $after{$sbstr}||0; substr ($nstring, $pos, length ($sbstr)) = $sbstr; $after{$sbstr}=$pos+1; }
|
|---|