perl hash一例,供大家学习参考。
创建一个hash:
#creat a hash and output its value
%hash=(width=>'300',height=>'150');
print "$hash{'width'}= $hash{'width'}n";
print "$hash{'height'}=$hash{'height'}nn";
print "$hash['width']= $hash['width']n";
print "$hash['height']=$hash['height']nn";
#assigning to a new hash element
$hash{'color'}='blue';
print "$hash{'width'}= $hash{'width'}n";
print "$hash{'height'}=$hash{'height'}n";
print "$hash{'color'}=$hash{'color'}n";
#display a hash with print
print "%hashn";
print %hash,"n";