%friend=('fred'=>flintstone,'barney'=>rubble,'wilma'=>flintstone,);#构建哈希
print "Please input second name,and you will get the family name\n";
chomp($second_name=<>);#又一次忘记写chomp了
$family_name=$friend{$second_name};#哈希的取值
print "$family_name";
结果如下:
F:\>perl\a.pl
Please input second name,and you will get the family name
fred
flintstone
F:\>