// -- 代码大全2 实践 --
1.根据伪代码写实际代码
2.循环的控制结构,可以先写内层循环,再在外面套接一层循环
1.根据伪代码写实际代码
2.循环的控制结构,可以先写内层循环,再在外面套接一层循环
场景:Perl 的 Hash of Hash
目的:打印 Hash of Hash
定义HoH表
%HoH = ( flintstones => { husband => "fred",pal => "barney",},jetsons => { husband => "george",wife => "jane","his boy" => "elroy",# Key quotes needed. },simpsons => { husband => "homer",wife => "marge",kid => "bart",);
伪代码:
foreach the collections
get the family name
for the family
get the family roles
then print the member(key/values)
编写内层代码:
#implement the inner loop for $roles (keys % {$HoH{$family}}) { print "\t $roles => $HoH{$family}{$roles},\n"; }
套上外层代码:
for $family (keys %HoH) { print "$family=> {\n"; for $role (keys % {$HoH{$family}}) { print "\t $role => $HoH{$family}{$role},\n"; } print "},\n"; }