Difference between revisions of "Perl hash"
From Teknologisk videncenter
m (Created page with "<source lang=perl> my %hosts = ( "www" => "192.168.1.2", "intranet"=> "192.168.1.3", "mail" => "192.168.1.4"); print("IP adressen på www = $hosts{'...") |
m (moved Hashes perl to Perl hash) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
print("Host $k har IP adressen $v\n"); | print("Host $k har IP adressen $v\n"); | ||
} | } | ||
+ | print("------------------------ CHANGE VALUE ----------------------\n"); | ||
$hosts{"intranet"} = "80.80.80.80"; | $hosts{"intranet"} = "80.80.80.80"; | ||
my %reverseHosts = reverse %hosts; | my %reverseHosts = reverse %hosts; | ||
Line 37: | Line 38: | ||
} | } | ||
</source> | </source> | ||
+ | |||
+ | [[Category:Perl]] |
Latest revision as of 04:56, 18 June 2012
my %hosts = ( "www" => "192.168.1.2",
"intranet"=> "192.168.1.3",
"mail" => "192.168.1.4");
print("IP adressen på www = $hosts{'www'}\n");
my %reverseHosts = reverse %hosts;
print("Host med IP 192.168.1.2 hedder $reverseHosts{\"192.168.1.2\"}\n");
#Udskriv hele hash tabellen
my ($k,$v);
while ( ($k, $v) = each %hosts ) {
print("Host $k har IP adressen $v\n");
}
print("------------------------ CHANGE VALUE ----------------------\n");
$hosts{"intranet"} = "80.80.80.80";
my %reverseHosts = reverse %hosts;
print("#### hosts\n");
while ( ($k, $v) = each %hosts ) {
print("Host $k har IP adressen $v\n");
}
print("#### reverseHosts\n");
while ( ($k, $v) = each %reverseHosts ) {
print("Host $k har IP adressen $v\n");
}
print("-------------------------- ADD KEY/VALUE -------------------\n");
$hosts{"wiki"} = "80.80.80.81";
my %reverseHosts = reverse %hosts;
print("#### hosts\n");
while ( ($k, $v) = each %hosts ) {
print("Host $k har IP adressen $v\n");
}
print("#### reverseHosts\n");
while ( ($k, $v) = each %reverseHosts ) {
print("Host $k har IP adressen $v\n");
}