小骆驼图书第六章练习
1.
my %hash;
%hash = (
"fred" => "flintstone",
"barney" => "rubble",
"wilma" => "flintone",
); #注意使用的是**()** 括号还需要**;**结束;
print "please enter the first name :";
chomp($fir_name = <STDIN>);
print "the family name of the $fir_name is ",$hash{$fir_name},"\n"; #hash的调用也是用的**$**;
#! /perl -w
print "enter the word each line ,use the CTRL-D for over \n";
chomp(@words = <STDIN>);
my %times;
foreach(@words){
$times{$_} = $times{$_} + 1;
}
while(($word,$time) = each %times){ #从hash中同时获取key/value
print "$word => $time \n";
}