2011年10月19日 星期三

Perl:二維陣列的Assignment

#mutiAssign.pl
sub func{
    print "func invoked....$_[0],$_[1]\n";
    return "Hello".scalar($_[0]).scalar($_[1]);
}




for $x (1 .. 3) {
        for $y (1 .. 3) {
            print "(",$x,",",$y,"):";
            $LoL[$x][$y] = func($x, $y);
#all element of  two dims @LoL NOTE:get the return value of'func'!
            print "\n";
        }
    }
    
for $ele(@LoL){
    print $ele,"\n";#印出陣列的記憶體位置
    print @$ele,"\n";#印出陣列中全部的元素值


}




#輸出結果:

(1,1):func invoked....1,1


(1,2):func invoked....1,2


(1,3):func invoked....1,3


(2,1):func invoked....2,1


(2,2):func invoked....2,2


(2,3):func invoked....2,3


(3,1):func invoked....3,1


(3,2):func invoked....3,2


(3,3):func invoked....3,3






ARRAY(0x104a1440)
Hello11Hello12Hello13
ARRAY(0x104a1938)
Hello21Hello22Hello23
ARRAY(0x104a19b0)
Hello31Hello32Hello33

沒有留言:

張貼留言