in reply to Re^2: Can I avoid loops getting the single value from a hash without knowing the key?
in thread Can I avoid loops getting the single value from a hash without knowing the key?
But if there are multiple entries in the hash, LanX's suggestion will put the value of a randomly choosen hash entry in $value. This might not be what you want.
So I suggest defensive coding:
first check if the hash only holds one entry
if (1 == scalar keys %hash)
before (blindly) retrieving a value.
|
|---|