1
2
3
4
5
6
$food_color = (
Raspberry => "blue",
Apple => "green",
Banana => "yellow",
Cherry => "red"
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# food color per the introduction
foreach $name ("Banana", "Martini")
{
if(exists($food_color{$name}))
{
# it exists
print "$name is a food. \n";
}
else
{
# it doesn't
print "$name is a drink.\n";
}
}
1 2 3 4 5 6
$food_color = { Raspberry => "blue", Apple => "green", Banana => "yellow", Cherry => "red" };
if(exists($food_color->{$name}))
1
2
3
4
5
6
$food_color = (
Raspberry => "blue",
Apple => "green",
Banana => "yellow",
Cherry => "red"
);
2014-05-05T07:09:59 bandchefIch hab folgenden Hash angelegt:
Code: (dl )1
2
3
4
5
6$food_color = (
Raspberry => "blue",
Apple => "green",
Banana => "yellow",
Cherry => "red"
);