2011年10月18日 星期二

#refFunc.pl




sub somefunc{
  print "function invoked:",$_[0],"\n";
  return $_[0];
}
#將函數的返回值傳入陣列@LoL的元素
for $i ( 1 .. 10 ) {
        $LoL[$i] = somefunc($i) ;
    }
    
print "\@LoL=>",@LoL,"\n";


#使用list reference [] @refArr陣列元素存入函數的參照
for $i ( 1 .. 10 ) {
        $refArr[$i] = [somefunc($i)] ;
    }
print "\@refArr => @refArr";


#輸出結果

function invoked:1
function invoked:2
function invoked:3
function invoked:4
function invoked:5
function invoked:6
function invoked:7
function invoked:8
function invoked:9
function invoked:10
@LoL=>12345678910
function invoked:1
function invoked:2
function invoked:3
function invoked:4
function invoked:5
function invoked:6
function invoked:7
function invoked:8
function invoked:9
function invoked:10
@refArr =>  ARRAY(0x104a1890) ARRAY(0x104a18c0) ARRAY(0x104a1908) ARRAY(0x104a1950) ARRAY(0x104a1998) ARRAY(0x104a19e0) ARRAY(0x104a1a28) ARRAY(0x104a1a70) ARRAY(0x104a1ab8) ARRAY(0x104a1b00)



沒有留言:

張貼留言