×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Perl 问题

各位 Perl 高手,下面是一个子程序:

34 sbu fibonacci {
35 my $target = shift;
36 my ($a, $b) = (1, 0);
37 for (my $i = 1; $i <=$target; $i++) {
38 my $c = $a + $b;
39 print "fibonacci($i) => $c\n";
40 ($a, $b) = ($b, $c);
41 }
42 }

当我执行这个程序时,Perl 显示如下出错信息:

syntax error at ./facfib.pl line 36, near "my "
syntax error at ./facfib.pl line 42, near "}"
Execution of ./facfib.pl aborted due to compilation errors.

谁能告诉我36行,42行有什么错误?
Report

Replies, comments and Discussions:

  • 工作学习 / 学科技术讨论 / Perl 问题
    各位 Perl 高手,下面是一个子程序:

    34 sbu fibonacci {
    35 my $target = shift;
    36 my ($a, $b) = (1, 0);
    37 for (my $i = 1; $i <=$target; $i++) {
    38 my $c = $a + $b;
    39 print "fibonacci($i) => $c\n";
    40 ($a, $b) = ($b, $c);
    41 }
    42 }

    当我执行这个程序时,Perl 显示如下出错信息:

    syntax error at ./facfib.pl line 36, near "my "
    syntax error at ./facfib.pl line 42, near "}"
    Execution of ./facfib.pl aborted due to compilation errors.

    谁能告诉我36行,42行有什么错误?
    • 34行是"sub",而不是"sbu"
      • sharp eyes. thanks.