我从我的一位朋友那里得到了这段代码,但是因为我没有使用 perl,所以我不知道它是如何工作的。你能帮我理解吗?
该文件必须获得一个文件,其中包含一些显示延迟的数据并获得间隔内的累积分布函数。
#!/usr/bin/perl
#print "Starting converter on file $ARGV[0]\n";
if ($#ARGV < 2 || $#ARGV > 3) {
print "Usage: ac_hist_gen.pl <input file> <num intervals> <output file> [ <interval size> ]\n";
exit(-1);
}
open(infile,"$ARGV[0]") || die "Couldn't open $ARGV[0] for reading.\n";
open(outfile,">$ARGV[2]") || die "Couldn't open $ARGV[2] for writing.\n";
for ($i=0; $i< 100 / $ARGV[1]; $i++) {
$dist[$i] = 0;
$acum[$i] = 0;
}
$max=0;
if ($#ARGV == 2) {
while (<infile>) {
if ($_ > $max) {
$max=$_;
}
}
$intsize = $max / $ARGV[1];
} else {
$intsize= $ARGV[3];
}
close(infile);
#print "size is $numpkts, max is $max, div is $intsize , test is $test\n";
open(infile,"$ARGV[0]") || die "Couldn't open $ARGV[0] for reading.\n";
while (<infile>) {
$val = int($_ / $intsize);
if (($_ / $intsize) == $val) {
$dist[$val-1]++;
} else {
$dist[$val]++;
}
# print "val is $val\n";
}
for ($i=0; $i< $ARGV[1]; $i++) {
$limit = ($i+1) * $intsize;
$acum[$i]+= $dist[$i];
$acum[$i+1] = $acum[$i];
print outfile "$limit $acum[$i]\n";
}
close(outfile);