Click here to get back home

DRaw a blank on combinging two arrays

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
DRaw a blank on combinging two arrays Bill H 06-18-2008
Posted by Bill H on June 18, 2008, 3:16 pm
Please log in for more thread options
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

Posted by Jens Thoms Toerring on June 18, 2008, 4:29 pm
Please log in for more thread options
> 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

Posted by Bill H on June 18, 2008, 8:45 pm
Please log in for more thread options
On Jun 18, 4:29=A0pm, j...@toerring.de (Jens Thoms Toerring) 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 =3D join(@a,@b); but just ende=
d
> > 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
>
> =A0 @c =3D ( @a, @b );
>
> is all you need. If you instead want to append the elements from
> @b to @a you would do
>
> =A0 push @a, @b;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Regards, Jens
> --
> =A0 \ =A0 Jens Thoms Toerring =A0___ =A0 =A0 =A0j...@toerring.de
> =A0 =A0\__________________________ =A0 =A0 =A0http://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

Posted by Bart Lateur on June 18, 2008, 4:31 pm
Please log in for more thread options
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.

Similar ThreadsPosted
How to draw a tree/graph of a web site? September 11, 2007, 2:59 pm
use perl to draw Venn Diagram April 27, 2008, 7:59 pm
Difference between accessing arrays and associative arrays using a int index April 12, 2006, 12:58 am
comparing 2 arrays strings when the number/name of arrays is dynamic October 22, 2006, 3:19 am
Merging a blank hash June 8, 2006, 4:03 pm
print Location to blank window? September 4, 2004, 12:10 am
DBD/DBI failing to add a blank in a non-null field December 29, 2004, 5:49 pm
more than one set of records separated by blank lines July 19, 2005, 9:40 am
FAQ 4.32: How do I strip blank space from the beginning/end of a string? December 16, 2004, 6:03 pm
FAQ 4.32 How do I strip blank space from the beginning/end of a string? January 24, 2005, 6:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap