perl - Perl脚本中的奇数子例程编译错误

标签 perl compiler-errors subroutine

为了比较,分别将两段ASCII文本(一个L =长,一个S =短)读入@arrayOne和@arrayTwo。以下子例程&analyse从smart.pl代码中获取了两个数组引用,但是在通过perl -c smart.pl检查时抛出错误。不幸的是,我不知道为什么:

68  sub analyse {
69      my $arraysize ; my $arrLref ; my $arrSref ; my $item_L ; my $item_S ; my $value ;
70
71      $arrSref = shift ; $arrLref = shift ;
72      $item_S = shift @{ $arrSref } ;
73      $item_L = shift @{ $arrLref } ;
74
75      $arraysize = $#{ $arrSref } ;
76      while ( $arraysize > 0 ) {
77          $value = ( $item_S cmp $item_L ) ;
78          given ( $value ) {
79              when ( -1 ) {
80                  push ( @mergedArray , $item_S ) ;
81                  $item_S = shift @{ $arrSref }
82              }
83              when ( 0 ) {
84                  push ( @mergedArray , $item_L ) ;
85                  $item_S = shift @{ $arrSref } ;
86                  $item_L = shift @{ $arrLref }
87              }
88              when ( 1 ) {
89                  push ( @mergedArray , $item_L ) ;
90                  $item_L = shift @{ $arrLref }
91              }
92              default { &die }
93          }
94      }
95  }

使用以下语句中止编译:
    $ perl -c smart.pl 
    syntax error at smart.pl line 78, near ") {"
    syntax error at smart.pl line 83, near ") {"
    syntax error at smart.pl line 88, near ") {"
    Global symbol "$item_L" requires explicit package name at smart.pl line 89.
    Global symbol "$item_L" requires explicit package name at smart.pl line 90.
    Global symbol "$arrLref" requires explicit package name at smart.pl line 90.
    syntax error at smart.pl line 91, near "}"
    smart.pl had compilation errors.

也许其他人有线索?预先感谢–DrP-

最佳答案

根据Perl documentation,为了使用givenwhen,需要满足两个条件:

  • 您需要use feature "switch";
  • 您需要Perl 5.10.1+

  • 那应该可以解释您在第78、83和88行看到的内容。

    关于在第89行和第90行上看到的警告,这些警告与use strict;的使用有关,可以在here中找到关于这些警告的出色解释。

    关于perl - Perl脚本中的奇数子例程编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20450274/

    相关文章:

    c++ - 与友元函数混淆

    perl - 将数组传递给Perl length子例程时会发生什么?

    FORTRAN 中子程序的指针

    multithreading - 在perl中使用并发线程的简单方法?

    java - perl 文件句柄不读取名称中带有空格的文件

    perl - 如何根据可用的模块动态包含模块?

    C++ 错误 : Not declared in scope; Member function

    xml - 如何使用 XML::XPath 获取属性?

    java - 使用数组列表并出现错误

    perl - Perl 中的子例程与脚本