Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: adding items, but with interim results

by davido (Archbishop)
on Mar 30, 2013 at 15:45 UTC ( #1026286=note: print w/ replies, xml ) Need Help??


in reply to adding items, but with interim results

You ought to let us know what you've tried and where you're stuck. That way when we help you past the part you're stuck with, you can still turn it in as your own work, and you will have learned something along the way. Just asking for a solution will get you "our work", and leave you with a learning deficit that will need to be repaid before you comprehend the next assignment.

The most straightforward ways will probably use foreach or map, and will probably iterate over the indices of the array. But just for fun, here's a solution that you would never turn in, or put into production:

use strict; use warnings; my @array = qw( 0 1 3 2 3 4 2 ); my @sums; for( "@array" ) { push @sums, $1 + $2 while m/(\d+)\s(?=(\d+))/g; } { local $" = ', '; print "[ @sums ]\n"; }

Dave


Comment on Re: adding items, but with interim results
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026286]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-07-28 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls