gpt4 book ai didi

perl - 我将如何解决以下错误 "Undefined subroutine &main::resetCounters called at"?

转载 作者:行者123 更新时间:2023-12-01 05:36:00 26 4
gpt4 key购买 nike

我将如何解决以下错误“未定义的子例程 &main::resetCounters 调用于”?该子例程已经原型(prototype)化,但 Perl 仍然提示。以下代码是我遇到的问题:

#!/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 = ();
}

最佳答案

除非子例程有括号,否则不需要原型(prototype)。如果不包括括号,则没有问题。代码如下所示:

#!/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 = ();
}

关于perl - 我将如何解决以下错误 "Undefined subroutine &main::resetCounters called at"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8748941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com