將兩段ASCII文本(一個L = long和一個S = short)分別讀入@arrayOne和@arrayTwo進行比較。以下子例程& analyze從smart.pl代碼獲取兩個數組引用,但通過perl -c smart.pl進行檢查時會引發錯誤。不幸的是我想不通爲什麼:Perl腳本中的奇數子程序編譯錯誤
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.
也許別人有線索? THX提前-DrP-
你有'while($ arraysize> 0){...'你不需要'$ arraysize = $#{$ arrSref};'倒數第二個'}',所以循環終止,或者只是'while($#{$ arrSref}){...'並忽略'$ arraysize = $#{$ arrSref};'一起? – Kenosis
你使用的是哪個版本的perl?當聲明只在perl 5.18.0中可用... –
你可以在這裏發佈perl -v –