Re: perl cumulative module question



Thanks Everyone!! This should help.



On Sat, Nov 22, 2008 at 9:17 AM, Rob Dixon <rob.dixon@xxxxxxx> wrote:

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

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/





Relevant Pages

  • Re: [opensuse] iConcepts WebCam
    ... crashing for some odd reason). ... To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: [opensuse] Fwd: Apache message file grows very fast
    ... It is odd because it started two days ago with no apparent reason. ... have not modified that portion of the server. ... To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: [opensuse] Novell client for Linux
    ... Odd. ... about 10.0 or lack of support for it. ... To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: mysterious pdf file wont be printed, all others will!
    ... files that used odd page sizes. ... MS Windows Adobe Reader prints the file normally. ... in a gv (or any other PS file viewer) and see if you get the right ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Using answers package to create student solutions manual
    ... I hadn't really thought about skipping the announcements of the ... since a student solution manual is usually just the odd ... stick to "high level" commands in those. ... Do you always want to print all exercises? ...
    (comp.text.tex)

Loading