perl返回哈希和的键和值

#!/usr/bin/perl
#!/usr/bin/perl

%data = ('google'=>'google.com', 'runoob'=>'runoob.com', 'taobao'=>'taobao.com');

@names = keys %data;#该函数返回所有哈希的所有key的数组
#注意是数组
print "$names[0]\n";
print "$names[1]\n";
print "$names[2]\n";

%data2 = ('google'=>'google.com', 'runoob'=>'runoob.com', 'taobao'=>'taobao.com');

@urls = values %data2;#该函数返回所有哈希的所有value的数组
#注意是数组
print "$urls[0]\n";
print "$urls[1]\n";
print "$urls[2]\n";

posted @ 2019-09-01 10:52  朵朵奇fa  阅读(1152)  评论(0编辑  收藏  举报