加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

代码大全实践——Perl伪代码

发布时间:2020-12-16 00:09:37 所属栏目:大数据 来源:网络整理
导读:// -- 代码大全2 实践 -- 1.根据伪代码写实际代码 2.循环的控制结构,可以先写内层循环,再在外面套接一层循环 场景:Perl 的 Hash of Hash 目的:打印 Hash of Hash 定义HoH表 %HoH = ( flintstones = { husband = "fred",pal = "barney",},jetsons = { hus
// -- 代码大全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";
}

例子虽然简单,但是展示了代码大全的建议,伪代码的编写,编程格式以及在编码碰到问题时,如何降低思维复杂度等思路。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读