Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: adding items, but with interim results

by toolic (Chancellor)
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 taking refuge in the Monastery: (10)
As of 2014-11-21 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (114 votes), past polls