perl hash一例

发布时间:2020-08-26编辑:脚本学堂
perl hash一例,供大家学习参考。
创建一个hash:
复制代码 代码如下:#creat a hash and output its value
%hash=(width=>'300',height=>'150');
print "\$hash{

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";