Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

# type: perl throughput.pl <trace file> <required node> <granlarity> + > output file use diagnostics; $infile=$ARGV[0]; $tonode=$ARGV[1]; $granularity=$ARGV[2]; #we compute how many bytes were transmitted during time interval speci +fied #by granularity parameter in seconds $sum=0; $clock=0; open (DATA,"<$infile") || die "Can't open $infile $!"; while (<DATA>) { @x = split(' '); #column 1 is time if ($x[1]-$clock <= $granularity) { #checking if the event corresponds to a reception if ($x[0] eq 'r') { #checking if the destination corresponds to arg 1 if ($x[3] eq $tonode) { #checking if the packet type is TCP if ($x[4] eq 'tcp') { $sum=$sum+$x[5]; } } } } else { $throughput=$sum/$granularity; print STDOUT "$x[1] $throughput\n"; $clock=$clock+$granularity; $sum=0; } } $throughput=$sum/$granularity; print STDOUT "$x[1] $throughput\n"; $clock=$clock+$granularity; $sum=0; close DATA; exit(0);
  • Comment on solution for the problem Illegal division by zero at throughput.pl line 36, <DATA> line 4. at throughput.pl line 36
  • Download Code

Replies are listed 'Best First'.
Re: solution for the problem Illegal division by zero at throughput.pl line 36, <DATA> line 4. at throughput.pl line 36
by toolic (Bishop) on Jul 20, 2016 at 17:21 UTC
    I see two places where you perform a division, and both simply divide by $granularity. My guess is that you didn't provide a 3rd argument to your throughput.pl command or the value you provided resolves to 0.

    Basic debugging checklist

    Writeup Formatting Tips