【发布时间】:2012-01-03 12:31:09
【问题描述】:
我有一个简单的散列,并希望根据 $value 条件返回 $key。也就是说,对于第 14 行,我需要什么代码来返回 $value 为“黄色”的 $key?
1 #!/usr/bin/perl
2
3 # This program creates a hash then
4 # prints out what is in the hash
5
6 %fruit = (
7 'apple' => ['red','green'],
8 'kiwi' => 'green',
9 'banana' => 'yellow',
10 );
11
12 print "The apple is @{$fruit{apple}}.\n";
13 print "The kiwi is $fruit{kiwi}.\n";
14 print "What is yellow? ";
【问题讨论】: