ben perl wrote: > Is there a perl module to find cumulative in a column? It should subtract > from the previous row and creates new column. > > For example, If i have the follow column in my file > > 2 > 6 > 9 > > It gives me > > 2 > 6-2 = 4 > 9-4 = 2 > > So the resulting column is > > 2 > 4 > 2 > > Hope I am using cumulative as the right word to explain this. > > I could write my own script but did not want to reinvent the wheel.
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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/