DRaw a blank on combinging two arrays

Discussion in 'Perl Misc' started by Bill H, Jun 18, 2008.

  1. Bill H

    Bill H Guest

    Earlier I was trying to combing 2 arrays and totally drew a blank on
    how to do it. I though it would be join but didn't seem to work. Can
    someone tell me what to look up in perldoc for it?

    I thought I could used something like @c = join(@a,@b); but just ended
    up with one long string.

    Bill H
     
    Bill H, Jun 18, 2008
    #1
    1. Advertising

  2. Bill H <> wrote:
    > Earlier I was trying to combing 2 arrays and totally drew a blank on
    > how to do it. I though it would be join but didn't seem to work. Can
    > someone tell me what to look up in perldoc for it?


    > I thought I could used something like @c = join(@a,@b); but just ended
    > up with one long string.


    It's not clear what you mean exactly with "combine to arrays", but
    your attempt with join makes it look as you simply want to append
    the elements of @b to that of @a and have the result in a third
    array. And in that case the you're looking for too complicated a
    solution, a simple

    @c = ( @a, @b );

    is all you need. If you instead want to append the elements from
    @b to @a you would do

    push @a, @b;
    Regards, Jens
    --
    \ Jens Thoms Toerring ___
    \__________________________ http://toerring.de
     
    Jens Thoms Toerring, Jun 18, 2008
    #2
    1. Advertising

  3. Bill H

    Bart Lateur Guest

    Bill H wrote:

    >Earlier I was trying to combing 2 arrays and totally drew a blank on
    >how to do it. I though it would be join but didn't seem to work. Can
    >someone tell me what to look up in perldoc for it?
    >
    >I thought I could used something like @c = join(@a,@b); but just ended
    >up with one long string.


    Simple enough:

    @c = (@a, @b);

    or

    @c = @a; # copy @a
    push @c, @b; # add @b

    --
    Bart.
     
    Bart Lateur, Jun 18, 2008
    #3
  4. Bill H

    Bill H Guest

    On Jun 18, 4:29 pm, (Jens Thoms Toerring) wrote:
    > Bill H <> wrote:
    > > Earlier I was trying to combing 2 arrays and totally drew a blank on
    > > how to do it. I though it would be join but didn't seem to work. Can
    > > someone tell me what to look up in perldoc for it?
    > > I thought I could used something like @c = join(@a,@b); but just ended
    > > up with one long string.

    >
    > It's not clear what you mean exactly with "combine to arrays", but
    > your attempt with join makes it look as you simply want to append
    > the elements of @b to that of @a and have the result in a third
    > array. And in that case the you're looking for too complicated a
    > solution, a simple
    >
    >   @c = ( @a, @b );
    >
    > is all you need. If you instead want to append the elements from
    > @b to @a you would do
    >
    >   push @a, @b;
    >                            Regards, Jens
    > --
    >   \   Jens Thoms Toerring  ___      
    >    \__________________________      http://toerring.de


    Thanks Jens - yeah thats what I wanted to do and I just could not
    figure it out - new it was simple but I was looking for something
    complex instead of thinking simple!

    Bill H
     
    Bill H, Jun 19, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    3
    Views:
    1,480
    Sandip Chitale
    Sep 30, 2003
  2. Philipp
    Replies:
    21
    Views:
    1,171
    Philipp
    Jan 20, 2009
  3. Kev Jackson
    Replies:
    2
    Views:
    136
  4. Joshua Muheim
    Replies:
    8
    Views:
    210
    Dejan Dimic
    Nov 23, 2007
  5. Allen Walker

    Merging two arrays -> array of arrays

    Allen Walker, May 21, 2010, in forum: Ruby
    Replies:
    6
    Views:
    179
    Jesús Gabriel y Galán
    May 21, 2010
Loading...

Share This Page