in reply to control+data structures for multi-line math on csv
This should get you started. It doesn't give the results you want althought it seems to follow what you said you wanted. Must have misunderstood :-) I just read of the DATA filehandle so you will have to open your input and output files. We localise the change to $, to this block to save suprises. The last line data is in @last which we initialise to '' values to keep warnings happy
use strict; use warnings; { local $, = ','; # print will print CSV with this set to ',' my @last = (0) x 7; # initialize array to 0's while(<DATA>) { chomp; next if /^\s*$/; # skip blank lines my @data = split','; # split out line into an array my $deltatime = $data[2]-$last[2]; next unless $deltatime; # protect against illegal div zero my $bps = ( $data[5] + $data[6] ) / $deltatime; print @data[0,1,3,4], $bps, "\n"; # this will be CSV @last = @data; # remember last line content } } # Collected data csv: # date,time,epochSec,device,ifIndex,ifInOctets,ifOutOctets, __DATA__ 2001-08-10,18:15:00,997485300,boston,141,1916238333,2743654663, 2001-08-10,18:18:12,997485492,boston,141,1917535505,2744657633, 2001-08-10,18:21:23,997485683,boston,141,1919320447,2747461877, 2001-08-10,18:24:34,997485874,boston,141,1921869420,2748722088, 2001-08-10,18:27:46,997486066,boston,141,1925884600,2764661750, 2001-08-10,18:30:57,997486257,boston,141,1929925399,2766849525,
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|