in reply to control+data structures for multi-line math on csv
From what you look to be asking, is for a good control structure to push your data through a calculation subroutine?? The best way is to is to use a subroutine.
# Init vars $prev_xists = "0"; @output = ""; @lines = get_lines(); @outlines = calc_lines(@lines) sub get_lines { ...... #perl code for getting lines } sub calc_lines { for (@_) { #Split out your data from the line my ($date, $time, $epochSec, $dev, $ifIdx, $ifIn, $ifOut, $nul) = spli +t ','; if ($prev_xists) { my $dTime = $old_epochSec - $epochSec; my $bps = ($ifIn + $ifOut) / $dTime; } else { my $bps = ""; } $old_epochSec = $epochSec; $prev_xists = "1"; my $new_line = "$date,$time,$dev,$ifIdx,$bps"; push @output, $new_line ; } return @output; }
This is not the most elegant solution, and there's some things I would change here and there, but this should get you started.
After all that you should have your data in @outlines.
~Hammy
|
|---|