Dave Adams wrote:
 %vegetable_costs  =     (Beans  => 300
                               Carrots => 200,
                               Apple   => 250 );

Apples are a vegetable?

To get the value of the key called Beans you use $vegetable_costs{Beans} .

How do you do the reverse and get the value of the key?

If all the costs are unique:

my %cost_lookup = reverse %vegetable_costs;

print "$cost_lookup{300} costs 300.\n";


If you expect that many vegetables have the same cost then:

my %cost_lookup;

push @{ $cost_lookup{ $vegetable_costs{$_} } }, $_ for keys %vegetable_costs;

print "The vegetable(s) @{$cost_lookup{300}} cost 300.\n";



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to