Professional Web Applications Themes

Inserting short strings into longer strings -- strncpy in Perl? - PERL Beginners

Edward Wijaya wrote:  perldoc -f substr -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl...

  1. #1

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

    Edward Wijaya wrote: 

    perldoc -f substr

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  2. #2

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

    Gunnar Hjalmarsson wrote: 

    and

    perldoc -f rand

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  3. #3

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

    On Sep 3, Edward Wijaya said:
     

    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

    Jeff Guest

  4. #4

    Default Inserting short strings into longer strings -- strncpy in Perl?

    Hi,

    Suppose I have these two arrays:

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

    #the starting position to be copied to in arr1 can is random.

    Thanks for your time.

    Regards,
    Edward WIJAYA
    SINGAPORE
    Edward Guest

  5. #5

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

    From: Jeff 'japhy' Pinyan <mailto:org> 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

    Charles Guest

  6. #6

    Default Problems installing DBD-Interbase on Fedora

    Hi, everybody!

    I have to work with FireBird database, for a project of mine.

    I grabbed from CPAN a DBD-InterBase (version 0.43) to work with, and
    installed it on Windows. It works perfectly.

    I also installed it on Red Hat 9 at my work place and it works very well.
    The problems started when I tried to install DBD-Interbase on Fedora, at my
    client's place.

    I get the same error no matter what version of DBD-Interbase I use.

    When I type "make" I get the following error:

    "Error: Cannot p function definition from 'strEQ(item, #name)) { \' in
    Interbase.xs, line 478 ' in Interbase.xs, line 487n definition from'
    keyname = #name;
    make: *** [InterBase.c] Error 1"


    Can anyone tell me where is the problem or what does this error message
    mean?

    Or what can I do, to make it work?

    Any help is highly appreciated.
    Cristi Ocolisan.

    Cristi Guest

  7. #7

    Default Re: Problems installing DBD-Interbase on Fedora

    On Fri, 3 Sep 2004, Cristi Ocolisan wrote:
     

    This sounds like a possible problem with the module itself, but I don't
    know anything about Interbase, so I'm not sure where to start.

    You may have better luck by trying either the DBI list, or if you get no
    help there, contact the module authors directly.

    Information on the DBI users list is available here:

    <http://lists.perl.org/showlist.cgi?name=dbi-users>
    <http://www.mail-archive.com/org/>

    According to CPAN.org, DBD::Interbase was written by Edwin Pratomo
    <org> and Daniel Ritz <ch>:

    <http://search.cpan.org/~edpratomo/DBD-InterBase-0.43/InterBase.pm>

    It may also be worth contacting these two for suggestions.

    Or maybe someone here will speak up, but I think in this case you'll
    have more luck by going to the module specific list for advice...


    --
    Chris Devers com
    http://devers.homeip.net:8080/blog/

    np: 'The Greatest Phone Message of All Time'
    by Jonathan Goldstein
    from 'This American Life: Crimebusters and Crossed Wires'
    Chris Guest

  8. #8

    Default RE: Problems installing DBD-Interbase on Fedora


    Hi Chris,

    I already asked on perl.dbi.users this question and I got only one response.
    It seems that I have to ask the authors directly.

    Anyway, I found a different driver, called Bundle::DBD::InterBase that works
    also on Fedora.

    Thank you.

    -----Original Message-----
    From: Chris Devers [mailto:com]
    Sent: 3 septembrie 2004 17:26
    To: Cristi Ocolisan
    Cc: org
    Subject: Re: Problems installing DBD-Interbase on Fedora

    On Fri, 3 Sep 2004, Cristi Ocolisan wrote:
     

    This sounds like a possible problem with the module itself, but I don't
    know anything about Interbase, so I'm not sure where to start.

    You may have better luck by trying either the DBI list, or if you get no
    help there, contact the module authors directly.

    Information on the DBI users list is available here:

    <http://lists.perl.org/showlist.cgi?name=dbi-users>
    <http://www.mail-archive.com/org/>

    According to CPAN.org, DBD::Interbase was written by Edwin Pratomo
    <org> and Daniel Ritz <ch>:

    <http://search.cpan.org/~edpratomo/DBD-InterBase-0.43/InterBase.pm>

    It may also be worth contacting these two for suggestions.

    Or maybe someone here will speak up, but I think in this case you'll
    have more luck by going to the module specific list for advice...


    --
    Chris Devers com
    http://devers.homeip.net:8080/blog/

    np: 'The Greatest Phone Message of All Time'
    by Jonathan Goldstein
    from 'This American Life: Crimebusters and Crossed Wires'

    Cristi Guest

  9. #9

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

     


    Yes, you are right Charles.
    And thanks so much too for Gunnar and Jeff.

    Best,
    Edward WIJAYA
    SINGAPORE
    Edward Guest

Similar Threads

  1. Inserting long strings into CLOB column
    By cfcoder2 in forum Coldfusion Database Access
    Replies: 1
    Last Post: October 20th, 01:03 PM
  2. Extracting strings delimited by other strings
    By Scott Bass in forum PERL Modules
    Replies: 2
    Last Post: May 7th, 02:26 AM
  3. inserting a string in between two other strings
    By DBSMITH@OhioHealth.com in forum PERL Beginners
    Replies: 4
    Last Post: April 8th, 06:10 PM
  4. Inserting strings into a file
    By Steve in forum PERL Beginners
    Replies: 2
    Last Post: March 2nd, 08:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139