RE: Inserting short strings into longer strings -- strncpy in Perl?

2004-09-03 Thread Charles K. Clarkson
From: Jeff 'japhy' Pinyan mailto:[EMAIL PROTECTED] wrote:

: On Sep 3, Edward Wijaya said:
: 
: : @arr1 =('GATGGATTAAAGGAGAGGTACTTACAGG',
: : 'CGCCCAAGAGGCCAGAGCGGAGCA',
: : 'CGTTAATGCATTAAAGTTCT');
: : 
: :@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',
: : 'CGCCCAAGAGGCCAGaggccacCA',
: : 'CGTTAAagctgcgAAGTTCT');
: 
: 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




Re: Inserting short strings into longer strings -- strncpy in Perl?

2004-09-03 Thread Edward WIJAYA

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

Yes, you are right Charles.
And thanks so much too for Gunnar and Jeff.
Best,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Inserting short strings into longer strings -- strncpy in Perl?

2004-09-02 Thread Gunnar Hjalmarsson
Edward Wijaya wrote:
Suppose I have these two arrays:
@arr1 =('GATGGATTAAAGGAGAGGTACTTACAGG',
'CGCCCAAGAGGCCAGAGCGGAGCA',
'CGTTAATGCATTAAAGTTCT');
   @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',
'CGCCCAAGAGGCCAGaggccacCA',
'CGTTAAagctgcgAAGTTCT');
#the starting position to be copied to in @arr1 can is random.
perldoc -f substr
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Inserting short strings into longer strings -- strncpy in Perl?

2004-09-02 Thread Jeff 'japhy' Pinyan
On Sep 3, Edward Wijaya said:

@arr1 =('GATGGATTAAAGGAGAGGTACTTACAGG',
 'CGCCCAAGAGGCCAGAGCGGAGCA',
 'CGTTAATGCATTAAAGTTCT');

@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',
 'CGCCCAAGAGGCCAGaggccacCA',
 'CGTTAAagctgcgAAGTTCT');

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);

-- 
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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




Re: Inserting short strings into longer strings -- strncpy in Perl?

2004-09-02 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote:
perldoc -f substr
and
perldoc -f rand
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response