通过引用传递数组参数

 
 
 

数组是通过引用传递的。如果将数组作为参数传递到某过程并在该过程中修改此参数,则数组将在从过程调用返回时具有修改的值。例如:

proc fred( string $myArray[] ) {
 for ( $i=0; $i<size($myArray); ++$i ) {
 $myArray[$i] = "fred";
 }
 $myArray[$i] = "flintstone"; // add to the end of the array.
 }
 string $a[] =`ls -geometry`;
 print("Before call to fred\n");
 print $a;
 fred($a);
 print("After call to fred\n");
 print $a;
produces this output: 
Before call to fred
nurbConeShape1
nurbConeShape2
nurbSphereShape1
nurbSphereShape2
After call to fred
fred
fred
fred
fred
flintstone