Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DRaw a blank on combinging two arrays

Reply
Thread Tools

DRaw a blank on combinging two arrays

 
 
Bill H
Guest
Posts: n/a
 
      06-18-2008
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
 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      06-18-2008
Bill H <(E-Mail Removed)> 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://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
 
Bart Lateur
Guest
Posts: n/a
 
      06-18-2008
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.
 
Reply With Quote
 
Bill H
Guest
Posts: n/a
 
      06-19-2008
On Jun 18, 4:29*pm, (E-Mail Removed) (Jens Thoms Toerring) wrote:
> Bill H <(E-Mail Removed)> 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 *___ * * *(E-Mail Removed)
> * *\__________________________ * * *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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 4.43 How do I compute the difference of two arrays? How do I compute the intersection of two arrays? PerlFAQ Server Perl Misc 0 02-02-2011 05:00 AM
Merging two arrays -> array of arrays Allen Walker Ruby 6 05-21-2010 08:31 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Two arrays: return only values that exist in both arrays? Joshua Muheim Ruby 8 11-23-2007 07:04 PM
two arrays problem (although different from the other two arrays) Kev Jackson Ruby 2 03-29-2006 03:58 PM



Advertisments