Chinaunix首页 | 论坛 | 博客
  • 博客访问: 858883
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-10-10 15:19:54

%ip_address = reverse %host_name;

it will reverse the value to key, the key to value of very item.

the value should be unique.

The keys function yields a list of all the keys in a hash, while the values function gives
the corresponding values. If there are no elements to the hash, then either function
returns an empty list:

  1. my %hash = ("a" => 1, "b" => 2, "c" => 3);
  2. my @k = keys %hash;
  3. my @v = values %hash;

  4. @k: a b c
  5. @v: 1 2 3
 each function, which returns a key-value pair as a two-element
list
  1. #!/usr/bin/perl
  2. #
  3. use strict;

  4. my %h = ("test"=>1,
  5.         "this"=>2);

  6. while (my ($key, $value) = each %h){
  7.     print $key, $value;
  8. }
To see whether a key exists in, use the exists function,
  1. if(exists $hash{$key1}){
  2.     print "can find it.";
  3. }
The delete function removes the given key (and its corresponding value) from the hash.
my $person = "betty";
delete $books{$person}; 


阅读(424) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~