I'm trying to learn hashes to incorporate into many places where arrays
seem a little too "bulky" but I've got a question regarding returning a
single key when I know a single value in the hash.
I've figured out the following (feel free to correct if I've got something
wrong):
my %test=(joe,smith,mike,garner);
@fnames=keys(%test); #all the first names, the keys
@lnames=values(%test); # all last names, the values
$mike_last_name=$test{"mike"}; #returns 1 value when I know the key.
How do I do the opposite of the above statement? How do I say:
Return the first name (key) for the person who's last name (value) is
"garner" ?
I think I figured out one way but I'm just curious to know if I've missed
something and there's a better way to do it without creating a second hash
like this:
%test2= reverse %test;
$garner_last_name=$test2{"garner"};
Any ideas? Or is this exactly how it should be done?
Thanks in advance.
Mike
--------------------------------------------------------------
Mike Garner
Western State College
Email: [email protected]
Voice: 970-943-3123
Fax: 970-943-7069