Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Get hash value with the lowest key

by Elgon (Curate)
on Jun 14, 2004 at 09:32 UTC ( #366456=note: print w/replies, xml ) Need Help??

in reply to Get hash value with the lowest key

Hi Kiat,

Because of the way that hashes are stored in memory, the order of keys returned is not guaranteed to be ordered or even consistent. If you want to get the lowest key, then something like...

my @ordered_list = sort keys %myhash;

...will put the lowest key (sorted asciibetically) into the $ordered_list[0] element. See this and this for futher info on sort and keys.

Hope this helps.


Update: Or you could use Foxcub's far more elegant solution!

"Stercus! Dixit Pooh. Eeyore, missilis lux navigii heffalumporum iaculas. Piglet, mecum ad cellae migratae secundae concurras."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://366456]
[ovedpo15]: how to check with regex that string has ",0" (notice the comma) but it 0 is the last char. for example: "hey,0" = good, "a,0" = good, "a,01" = bad, "hey,010101" = bad
[ovedpo15]: also "hey,010" is bad. only ",0 *end of string*"
[choroba]: /,0$/

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-03-20 07:40 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.