Study perl step by step ...... 今天学到Perl语言入门(第四版)Chapter 6, Hash 哈希。
#!/ap/local/5.8/bin/perl -w
my %books=(
"Alice" => "C",
"Bob" => "Java",
"Caselin" => undef,
"Davie" => "ASP",
"Marry" => "Java",
);
&print_hash(%books);
my %names=(
"pcl" => "Piao",
"yeer" => "Yao",
"Sincky" => "Zhang",
);
&print_hash(%names);
sub print_hash{
my %hash = @_; #### 这条语句非常关键!.
print "The current hash is:n";
while (($key,$value) = each %hash) {
print "$key => $valuen";
}
}
++++++++++++++++++++++++++++++++++++++++
$ pthash.pl
The current hash is:
Davie => ASP
Bob => Java
Marry => Java
Alice => C
Caselin =>
The current hash is:
Sincky => Zhang
yeer => Yao
pcl => Piao
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/126198/viewspace-912815/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/126198/viewspace-912815/