Use parentheses with the shift command!
The following generates an error:sub handleArray { my(@localArray) = @{shift}; my($element); foreach $element (@localArray) {print $element . "\n";} } &handleArray(\@globalArray);
But once you place the shift command in parens, everything's fine:
sub handleArray
{
my(@localArray) = @{(shift)};
my($element);
foreach $element (@localArray) {print $element . "\n";}
}
&handleArray(\@globalArray);
沒有留言:
張貼留言