From: Jeff 'japhy' Pinyan <mailto:[EMAIL PROTECTED]> wrote:

: On Sep 3, Edward Wijaya said:
: 
: : @arr1 =    ('GATGGATTAAAGGAGAGGTACTTACAGG',
: :             'CGCCCAAGAGGCCAGAGCGGAGCGGGGA',
: :             'CGTTAATGCATTAATTTTAGTTAAAACT');
: : 
: :    @arr2 = ('tcctcta',
: :             'aggccac',
: :             'agctgcg');
: : 
: : 
: : Is there any efficient way to copy each element
: : of @arr2 as part of each elements in @arr1
: : such that it gives result:
: : 
: : @arr3 =    ('GAtcctctaAAGGAGAGGTACTTACAGG',
: :             'CGCCCAAGAGGCCAGaggccacCGGGGA',
: :             'CGTTAAagctgcgATTTTAGTTAAAACT');
: 
: Use substr($str, $pos, 0, $addition) to insert $addition into
: $str at position $pos. 
: 
:   $a = "perl";
:   $b = "t ea";
:   substr($a, 2, 0, $b);
:   print $a;  # "pet earl"
: 
: To get a random position, I'd use:
: 
:   substr($big, rand(length $big), 0, $small);

    @array3 indicates the string was to overwrite at a
random position. I assume the entire string must be inside
the result.

my $start = length( $big ) - length( $small ) + 1;

substr( $big, rand $start, length $small ) = $small;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to