Adding together Perl Arrays

Posted on 2012-08-11
Last Modified: 2013-12-25
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?

Question by:Aaron Street
    LVL 26

    Accepted Solution

    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).
    LVL 16

    Author Comment

    by:Aaron Street
    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now