2011年10月15日 星期六

shift加上括弧的組合計 my(@localArray) = @{(shift)};


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);

沒有留言:

張貼留言