RE: Returning the first key in a hash...

2003-06-12 Thread Charles K. Clarkson
Hamish Whittal <[EMAIL PROTECTED]> wrote: : : I have a hash that looks like: : : { number => {somethings in here} } : : Now I need to get at number, not what it references. my %hash = ( number => {} ); foreach my $key ( keys %hash ) { # do something with each key ($key) } Since your h

Re: Returning the first key in a hash...

2003-06-12 Thread James Edward Gray II
On Thursday, June 12, 2003, at 07:30 AM, Hamish Whittal wrote: I have a hash that looks like: { number => {somethings in here} } Now I need to get at number, not what it references. If I understand correctly, you're trying to get the lowest number hash key. That we can do. Try: my $lowest =

Re: Returning the first key in a hash...

2003-06-12 Thread Sudarshan Raghavan
Rob Dixon wrote: Hamish Whittal wrote: Ok, thanks Sudarshan, but why did this not work? pop ( keys (%hash) ); 'pop' operates on an array, not a list. This would work my @keys = keys %hash; my $key = pop @keys; I guess you meant shift (@keys), pop will return the last key returned by

Re: Returning the first key in a hash...

2003-06-12 Thread Sudarshan Raghavan
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 fir

Re: Returning the first key in a hash...

2003-06-12 Thread Rob Dixon
Hamish Whittal wrote: > Ok, thanks Sudarshan, but why did this not work? > > pop ( keys (%hash) ); 'pop' operates on an array, not a list. This would work my @keys = keys %hash; my $key = pop @keys; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail

RE: Returning the first key in a hash...

2003-06-12 Thread Hamish Whittal
I have a hash that looks like: { number => {somethings in here} } Now I need to get at number, not what it references. Tx. H On Thu, 2003-06-12 at 14:22, Charles K. Clarkson wrote: > Hamish Whittal <[EMAIL PROTECTED]> wrote: > : > : I have a hash and want to return the first key in > : the hash

Re: Returning the first key in a hash...

2003-06-12 Thread Hamish Whittal
Ok, thanks Sudarshan, but why did this not work? pop ( keys (%hash) ); 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 (%yo

RE: Returning the first key in a hash...

2003-06-12 Thread Charles K. Clarkson
Hamish Whittal <[EMAIL PROTECTED]> wrote: : : I have a hash and want to return the first key in : the hash. How can I do this? You can't. The keys of a hash are unordered. there is no first key (or second key, or lastkey, etc.) To get a "first key", you'll have to define what a "first key" is

RE: Returning the first key in a hash...

2003-06-12 Thread Rai,Dharmender
darshan Raghavan[SMTP:[EMAIL PROTECTED] > Sent: Thursday, June 12, 2003 6:09 PM > To: [EMAIL PROTECTED] > Subject: Re: Returning the first key in a hash... > > > > Hamish Whittal wrote: > > >Hi all, > > > >I have a hash and want to return t

Re: Returning the first key in a hash...

2003-06-12 Thread Sudarshan Raghavan
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 re