9.4 散列的散列
多维的散列是perl里面最灵活的嵌套结构,它就好像绑定一个记录,该记录本身包含其他记录。
9.4.1 构成一个散列的散列
你可以用下面方法创建一个匿名散列的散列:
Vsftp:/root/perl/6# cat a12.pl
%HoH = (
flintstones => {
husband => "fred",
pal => "barney",
},
jetsons => {
husband => "george",
wife => "jane",
"his boy" => "elroy", # 键字需要引号
},
simpsons => {
husband => "homer",
wife => "marge",
kid => "bart",
},
);
print %HoH;
print "\n";
print $HoH{'flintstones'}->{'pal'};
print "\n";
Vsftp:/root/perl/6# perl a12.pl
simpsonsHASH(0x1cf3750)jetsonsHASH(0x1cf3408)flintstonesHASH(0x1cd6d48)
barney
要向%HoH 中增加另外一个匿名散列,你可以简单地说:
$HoH{ mash } = {
captain => "pierce",
major => "burns",
corporal=> "radar",
};
Vsftp:/root/perl/6# cat a12.pl
%HoH = (
flintstones => {
husband =>
9.4 散列的散列
最新推荐文章于 2024-09-05 19:25:11 发布
