Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: adding items, but with interim results

by toolic (Bishop)
on Mar 30, 2013 at 15:06 UTC ( #1026281=note: print w/ replies, xml ) Need Help??


in reply to adding items, but with interim results

3+2=6??

use warnings; use strict; my @array = qw (0 1 3 2 ) ; my @newarray = $array[0]; for my $i (1 .. $#array) { push @newarray, $array[$i-1] + $array[$i]; } print "@newarray\n"; __END__ 0 1 4 5

Or, maybe your spec is ambiguous:

my @array = qw (0 1 3 2); my @newarray = $array[0]; my $sum = $array[0]; for my $i (1 .. $#array) { $sum += $array[$i]; push @newarray, $sum; } print "@newarray\n"; __END__ 0 1 4 6


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://1026281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2015-07-04 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls