the function is:
sub parse_standard
{
my $filename = "myDocuments\\me\\info.csv";
#first, calculate the Avg and the number of rows
open(INPUT, $filename) or die "Cannot open $filename";
# Read the header line.
my $line = <INPUT>;
my $sum = 0 ;
my $counter = 0;
#Read the lines one by one.
while($line = <INPUT>)
{
chomp($line);
my ($Input,$Execution,$Output,$Total,$SelfTest,$Log_Location,$Log_Name) = split(',', $line);
$sum = $sum + $Input;
$counter = $counter +1;
}
$avg = $sum/$counter ;
#second , calculate the standard deviation
open(INPUT, $filename) or die "Cannot open $filename";
my $line = <INPUT>;
my $sum = 0 ;
#Read the lines one by one.
while($line = <INPUT>)
{
chomp($line);
my ($Input,$Execution,$Output,$Total,$SelfTest,$Log_Location,$Log_Name) = split(',', $line);
$diff = ($Input-$avg);
$square = $diff * $diff ;
$sum = $sum + $square;
}
$tosqrt = $sum/$counter;
$answer = sqrt($tosqrt);
print "standard deviation is $answer\n";
close(INPUT);
}
parse_standard();
是您的输入CSV文件?它看起来像你在列中。你在做什么数学?这是你的输出吗?你的输入是什么样的?你想表演什么数学?你知道多少Perl?我写作Perl脚本生活。我很乐意以我的标准费率115美元/小时完成这项工作。 – 2013-02-25 15:37:34
只是做一些研究如何吸取文本文件并解析出分隔字段。 – amphibient 2013-02-25 15:37:40