Gossamer Forum
Home : General : Perl Programming :

combining two arrays of numbers togethor

Quote Reply
combining two arrays of numbers togethor
Hi

I think this quite simple to do but i am quite new to perl and finding it hard to get my head around how to do this. I think I need to use a foreach function but am not entirely sure.

I have two arrays, each with a column of numbers, I want to combine the two arrays so that I have one array with both columns side by side. I have tried concatenating the arrays but this adds the columns underneath each other as a continuous array of numbers. I would prefer the columns to be side by side in the array.

Any help would be greatly appreciated

Thanks
Quote Reply
Re: [nxstar] combining two arrays of numbers togethor In reply to
Hi,

Need a bit more info in terms of what you're data looks like.

Try this debugging so we can see:

use Data::Dumper;
print Dumper(@array1,@array2);

...then view the page, and it should give you the "structure" of the array.

Once we know that, should be able to help you out ;)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] combining two arrays of numbers togethor In reply to
A snapshot of the two arrays are, i have roughly 4000 enteries in both arrays.
@endsite=
2796
3730
5017
9188
9890

@startsite=
2801
3734
8238
9306
12163

and I need it to look like

@combined=

2796 2801
3730 3734
5017 8238
9188 9306
9890 12163 ####So the data is organised into two columns in one array

I hope this makes more sense

Last edited by:

nxstar: Feb 12, 2009, 6:42 AM
Quote Reply
Re: [nxstar] combining two arrays of numbers togethor In reply to
Hi,

Try this:

Code:
for (my $i = 0; $i <= $#endsite; $i++) {
print qq|$endsite[$i] $startsite[$i]\n|;
}

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates