%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:
- my %hash = ("a" => 1, "b" => 2, "c" => 3);
-
my @k = keys %hash;
-
my @v = values %hash;
-
-
@k: a b c
-
@v: 1 2 3
each function, which returns a key-value pair as a two-element
list
- #!/usr/bin/perl
-
#
-
use strict;
-
-
my %h = ("test"=>1,
-
"this"=>2);
-
-
while (my ($key, $value) = each %h){
-
print $key, $value;
-
}
To see whether a key exists in, use the exists function,
- if(exists $hash{$key1}){
-
print "can find it.";
-
}
The delete function removes the given key (and its corresponding value) from the hash.
my $person = "betty";
delete $books{$person};
阅读(419) | 评论(0) | 转发(0) |