DRaw a blank on combinging two arrays

B

Bill H

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
 
J

Jens Thoms Toerring

Bill H said:
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
 
B

Bart Lateur

Bill said:
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
 
B

Bill H

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,687
Latest member
IngridXxj

Latest Threads

Top