Re: perl cumulative module question
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Sat, 22 Nov 2008 17:17:52 +0000
Rob Dixon wrote:
Your arithmetic is odd. You say
9-4 = 2
and so your resulting list should be (2,4,2). If you want to subtract the
previous result from the next item in your data list each time then this will do
the job.
HTH,
Rob
use strict;
use warnings;
my @data = (2, 6, 9);
my @delta = @data;
my $prev = 0;
$prev = $_ = $_-$prev for @delta;
print "@delta\n";
**OUTPUT**
2 4 5
Jay's solution is very similar but preferable to mine.
Rob
.
- Follow-Ups:
- Re: perl cumulative module question
- From: Ben Perl
- Re: perl cumulative module question
- References:
- perl cumulative module question
- From: "ben perl"
- Re: perl cumulative module question
- From: Rob Dixon
- perl cumulative module question
- Prev by Date: Re: perl cumulative module question
- Next by Date: How Do I Auto-Run Perl in a Browser
- Previous by thread: Re: perl cumulative module question
- Next by thread: Re: perl cumulative module question
- Index(es):
Relevant Pages
|