|
发表于 2004-4-26 23:07:37
|
显示全部楼层
你的程序经过修改,是这样,但输出的结果我不能解释??
print @{$array[$k]};是对的,应该这样写。
而print "$array[$k]";打印其实是数组所在的地址。
在man perldsc里有比较详细的分析。
……
Now, because the top level contains only references, if you try to print out your array in with a simple print() function, you'll get something that doesn't look very nice, like this:
[php]
@AoA = ( [2, 3], [4, 5, 7], [0] );
print $AoA[1][2];
7
print @AoA;
ARRAY(0x83c38)ARRAY(0x8b194)ARRAY(0x8b1d0)
[/php]
That's because Perl doesn't (ever) implicitly dereference your variables. If you want to get at the thing a reference is referring to, then you have to do this yourself using either prefix typing indicators, like ${$blah}, @{$blah}, @{$blah[$i]}, or else postfix pointer arrows, like $a->[3], $h->{fred}, or even $ob->method()->[3]. |
|