Possible Duplicate:
How to join two substrings in perl
How could I find a substring of a string array which corresponds to user entered index of character?
For example: If there is a string $string = 'MFHYRAKCLAMSCTLPHCAKNDHGCTH';and it get broken into array @string = ( "MFHYRA","KCLAM", "SCTLP", "HCAKNDHGCTH" ) ; now if user enters position of A as 6 and 10, how could two corresponding substrings be searched and joined?
Essentially, what you ask is this: we have a position in the initial string. The string gets split up in substrings. In which of the substrings is the position?
Assume that
is the list of positions for which you would like to find the substrings.
Clearly, this code could use some optimalization, for example — no need to loop over the elements of
@posif we already have a substring for them, and we should break the operation after the last element of@posgot its substring, but for a few positions entered for the user this doesn’t really matter.