【发布时间】:2023-04-04 18:01:01
【问题描述】:
递归函数运行时出现Perl错误如何解决
main::getE_Path_Rec() called too early to check prototype at ./test.pl line 28
由 cat -n 显示:
13 our ($whole, @result);
14
15 sub getE_Path_Rec ($\@$) { my ($path, @iOffNode, $offset) = @_;
16
17 $path=~ s#^/([^/]+)(.*)$#$2#;
18 my @OffNode; my $eleNow=$1;
19 for (@iOffNode) {
20 $eleNow=~ m#^([^[/,]+)(?|\[(\d+|@[^]]+)\]|,(\d+))?#;
21 #
22 if($2) {
23 getElem($1, $2-1, $_->[1], @OffNode);
24 return undef if !@OffNode;
25 if ($path) {
26 #
27 #
28 getE_Path_Rec( $path, @OffNode, $offset.${$OffNode[0]}[0])
29 }else {
30 push( @result, [$offset, ${$OffNode[0]}[1]])
31 }
36 }
37
38 return
39 }
我们如何在 Perl 中无缝解决递归函数?
【问题讨论】:
-
(1) 一个建议:总是很好地清理你发布的内容——删除那些行号(这样人们可以复制粘贴它进行测试),删除空行上的 cmets (?),排队大括号、缩进等 (2) 你确定那些
($whole, @result)需要是our吗?这是一个常见的错误——大多数时候他们应该是my -
@iOffNode是错误的。你想要$iOffNode。 //our应该是my// 而且我没有看到在这里使用原型的意义。它只会增加复杂性。
标签: perl