in reply to how to find a key from a hash
If there's one key in the hash, keys(%hash) will return a single element array (excuse me, I've gone into lecture mode...).
If you really don't care about which key you get from a hash with more than one entry, wouldn't
($key) = keys(%hash);
be perfectly adequate?
Incidentally, if there is going to be only one key in a hash or, if you've multiple keys and don't care which one you get, why are you using a hash?
Thanks to Perl Mouse for pointing out a horrid error on my part; for some inane reason I thought shift(keys(%hash)) was valid Perl.
emc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to find a key from a hash
by Perl Mouse (Chaplain) on Nov 21, 2005 at 16:04 UTC | |
by swampyankee (Parson) on Nov 21, 2005 at 16:17 UTC |