How would I solve the following error "Undefined subroutine &main::resetCounters called at"? The subroutine has been prototyped but still Perl complains. The following code is what I am having issues with:
#!/usr/bin/perl
use strict;
use warnings;
...
sub reportStats();
sub resetCounters(); #HERE IS THE PROTOTYPE
sub getUpperBusTimeStampAndBatchSize($);
sub toMs($);
sub tibTimeToMs();
sub calcStdDev();
...
print "\nTimeStamp TPS MPS MaxBat AvgBat MaxLat AvgLat StdLat >5ms %>5ms\n";
resetCounters(); #THIS IS THE LINE CONTAINING THE ERROR
...
sub resetCounters()
# -----------------------------------------------------------
# resets all metrics counters
# -----------------------------------------------------------
{
$tps = 0;
$mps = 0;
$batch = 0;
$maxBatch = 0;
$avgBatch = 0;
$latency = 0;
$latencySum = 0;
$maxLatency = 0;
$avgLatency = 0;
$overThreshold = 0;
$percentOver = 0;
$currentSecond = $second;
@latencies = ();
}
The prototype is not required except when the subroutine has parentheses. If you do not include parentheses then there is no issue. The code would look like:
#!/usr/bin/perl
use strict;
use warnings;
...
print "\nTimeStamp TPS MPS MaxBat AvgBat MaxLat AvgLat StdLat >5ms %>5ms\n";
resetCounters();
...
sub resetCounters #No parentheses
# -----------------------------------------------------------
# Resets all metrics counters
# -----------------------------------------------------------
{
$tps = 0;
$mps = 0;
$batch = 0;
$maxBatch = 0;
$avgBatch = 0;
$latency = 0;
$latencySum = 0;
$maxLatency = 0;
$avgLatency = 0;
$overThreshold = 0;
$percentOver = 0;
$currentSecond = $second;
@latencies = ();
}