Hi all,
Let me brief the basics of hash.
keys %hash; will return the keys available in Hash.
values %hash; will return the values available in Hash.
But Recently I met an Issue as follows :-
my %param;
foreach my $values ( sort values %user_details ) {
$param{user_name} = $values;
}
I will use the Above sorted user names to display in the web screen.
But suddenly I had a requirement like to get the keys of hash by using the hash values.
Is there a way to get the key of a hash using its values.
Because as per my understanding the keys of Hash can not be duplicate, Even if it is so there is no meaning in having that
$hash{1} = 'One';
$hash{1} = 'one';
# No use
can any one have Idea in getting this work ?
"Keep pouring your ideas"
2005-11-17 Retitled by Arunbear, as per consideration
Original title: 'Getting Keys of Hash'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.