Hamish Whittal wrote:

Ok, thanks Sudarshan, but why did this not work?

pop ( keys (%hash) );


perldoc -f pop pop works on arrays, keys returns a list (perldoc -f keys) perldoc -q 'What is the difference between a list and an array?'

Anyways, pop returns the last element of the array not the first. shift will return the first element of the array (perldoc -f shift)
But, shift will work on arrays only not lists.



Thanks. H
On Thu, 2003-06-12 at 14:39, Sudarshan Raghavan wrote:


Hamish Whittal wrote:



Hi all,

I have a hash and want to return the first key in the hash. How can I do
this?



The answer is (keys (%your_hash))[0]. This will return the first element in the list of hash keys returned by keys. But, you can never be sure of the order in which the keys will be retrieved. If you are worried about the order, take a look at the Tie::IxHash module.



Thanks in advance,

Hamish









-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to