gpt4 book ai didi

perl - 如何在没有 "called too early to check prototype"的情况下声明函数并递归使用它

转载 作者:行者123 更新时间:2023-12-04 14:08:27 32 4
gpt4 key购买 nike

我有一个通用的递归函数,但为什么它没有在 perl 中授权

sub pv($) {
my ($vars) = @_;
if(ref($vars) eq 'SNMP::Varbind') {
return $vars->tag() . (defined($vars->iid()) ? '.' . $vars->iid() : '');
} elsif (ref($vars) eq 'SNMP::VarList') {
return join(', ', map { pv($_) } @$vars);
} elsif(ref($vars) eq 'ARRAY') {
return join('.', @{$vars});
} else {
return $vars;
}
}

此行的此错误代码“pv() 调用太早无法检查原型(prototype)” return join(', ', map { pv($_) } @$vars);

最佳答案

简单:前向声明

sub pv($);
sub pv($) {

关于perl - 如何在没有 "called too early to check prototype"的情况下声明函数并递归使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54519375/

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