How to read multiple text file filled with columns calculating statistics perl -
i'm running network measurements ton of timestamps according picture: http://i.stack.imgur.com/tnnbf.png
i want statistics of mean, var & cov , problem have don't know how read in text files right values in right array.
i saw bash considered poor in area decided perl should better. attempt far:
#!/usr/bin/perl #foreach $line $pkt_number = $1; $pkt_arrival = $2; $pkt_size = $6; $nr_of_pkg = 16; $linespeed = 100000; $sum_of_throughput = 0; $throughput = 0; $sum_of_throughputsquared = 0; $mean = 0; $var = 0; $co_v = 0; $duration = $pkt_arrival[0] - $pkt_arrival[15]; (my $i = 0 ; $nr_of_pkg > $pkt_number[i] ; $i++) { $throughput[i] = $packet_size[i] / $pkt_arrival[i]; $sum_of_throughput = $sum_of_throughput + $throughput[i]; $sum_of_throughput_squared = $sum_of_throughput_squared + $throughput[i] * $throughput[i]; } $mean = $sum_of_throughput / $nr_of_pkg; $var = (($sum_of_throughput * $sum_of_throughput) - $sum_of_throughput_squared); $co_v = sqrt($var)
this code read , parse text file.
my @pkt_number; @pkt_arrival; @pkt_size; $i = 0; $line; while ( <> ) { $line = " $_"; # make sure start whitespace chomp $line; ( $pkt_number[$i], $pkt_arrival[$i], $pkt_size[$i] ) = (split( /\s+/, $line, 8 ))[ 1, 2, 6 ]; printf "[%s]\n", join("/", $pkt_number[$i], $pkt_arrival[$i], $pkt_size[$i]); $i++; }
and how run on linux :
% cat result.txt | ./your_perl.pl
Comments
Post a Comment