perl中hash数组的相关的例子

发布时间:2019-11-05编辑:脚本学堂
perl中hash数组的相关的例子,供大家学习参考。
复制代码 代码如下:#!/usr/bin/perl
my %hash1=("wilma"=>789,
"barney"=>456,
"dino"=>234);

perl中hash数组的相关的例子,供大家学习参考。
 

复制代码 代码如下:

#!/usr/bin/perl
my %hash1=("wilma"=>789,
           "barney"=>456,
           "dino"=>234);
my @k=keys %hash1;            # keys
my @v=values %hash1;          #values
print "@kn";
print "@vn";

while (($key,$value)=each %hash1){    #print
       print "$key=>$valuen";
  }
print "%hash1nn";

#delete 函数
my $person="wilma";
delete $hash1{$person};
while (($key,$value)=each %hash1){    #print
       print "$key=>$valuenn";
  }

#exsists function
if(exists $hash1{"dino"}){
     print "hey,there is a lib card for wilma!n";
}#!/usr/bin/perl
my %hash1=("wilma"=>789,   #给hash数组赋值
           "barney"=>456,
           "dino"=>234);
my @k=keys %hash1;            # keys
my @v=values %hash1;          #values
print "@kn";
print "@vn";

while (($key,$value)=each %hash1){    #print
       print "$key=>$valuen";
  }
print "%hash1n";

输出结果为:
barney dino wilma
456 234 789
barney=>456
dino=>234
wilma=>789
%hash1
barney=>456
dino=>234
hey,there is a lib card for wilma!