Adding together Perl Arrays

Can any one help me with the most efficient way to add together two arrays in Perl?

I have two arrays

my @Degre = map {rand(360)} (0..1999);
my @step= map {rand(.5)} (0..1999);

Open in new window

and have tried the following two methods to combine them

@Degre = map {$Degre[$_] + $step[$_]}0..1999;

$Degre[$_] += $step[$_] for (0..1999);

Open in new window

both work fine and for 2000 elements would be fine, but for 20,000 its starting to get slow and any thing above that its not very quick at all.

Are there any better / more efficient ways to combine arrays than cycling through them like this?

LVL 16
Aaron StreetInfrastructure ManagerAsked:
Who is Participating?
wilcoxonConnect With a Mentor Commented:
That's pretty much it unless you can find a special-purpose module on CPAN (I haven't heard of one for this but it may exist).
Aaron StreetInfrastructure ManagerAuthor Commented:
OK, So now I know why modeling requires such high throughput computing power.

My mates 96 core blade server he does disease modeling on is starting to make perfect sense :) Cheers.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.