Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   DRaw a blank on combinging two arrays (http://www.velocityreviews.com/forums/t907568-draw-a-blank-on-combinging-two-arrays.html)

Bill H 06-18-2008 07:16 PM

DRaw a blank on combinging two arrays
 
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

Jens Thoms Toerring 06-18-2008 08:29 PM

Re: DRaw a blank on combinging two arrays
 
Bill H <bill@ts1000.us> 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 ___ jt@toerring.de
\__________________________ http://toerring.de

Bart Lateur 06-18-2008 08:31 PM

Re: DRaw a blank on combinging two arrays
 
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.

Bill H 06-19-2008 12:45 AM

Re: DRaw a blank on combinging two arrays
 
On Jun 18, 4:29*pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> Bill H <b...@ts1000.us> 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 *___ * * *j...@toerring.de
> * *\__________________________ * * *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


All times are GMT. The time now is 12:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


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