Two pieces of ASCII text (one L = long and one S = short) were read into @arrayOne and @arrayTwo, respectively, for comparison. The following subroutine &analyse gets two array references from the smart.pl code, but throws an error when checked via perl -c smart.pl. Unfortunately I can't figure out why:
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 }
Compilation is aborted with the following statements:
$ 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.
Maybe someone else has a clue? Thx in advance –DrP-
while ( $arraysize > 0 ) { ...Don't you need$arraysize = $#{ $arrSref };above the second to last}, so the loop terminates, or justwhile ( $#{ $arrSref } ) { ...and omit$arraysize = $#{ $arrSref };altogether?