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 (added Category:Perl using HotCat) |
||
Line 37: | Line 37: | ||
} | } | ||
</source> | </source> | ||
+ | |||
+ | [[Category:Perl]] |
Revision as of 05:50, 31 May 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");
}
$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");
}