|Welcome to the Monastery|
Re^6: The error says the value is uninitialized, but it works anywayby afoken (Canon)
|on Aug 18, 2019 at 22:08 UTC||Need Help??|
Note that each in scalar context returns the next key.
One of the things I rarely use.
each iterates over the keys of a hash, returning different values when called repeatedly.
But the MUMPS $ORDER() function is different. Keys in MUMPS are always sorted, unlike Perl's hash keys. And keys must not be empty. $ORDER() returns the next key for the key you pass into. It does not iterate. Passing -1 as a second argument to $ORDER() returns the previous key instead of the next one. If there is no previous / next key, an empty string is returned.
Actually, $ORDER() is a "new" (*cough*) function, it can handle negative and non-numeric keys. The original function used to iterate over keys was $NEXT(), and it was intended to be used only with positive integers, i.e. plain arrays or sparse arrays. It returns -1 if no more keys can be found. Unfortunately, -1 is a legal key. So if $NEXT() returns -1, you can not know if you found the last key or you just happen to have -1 as a key. $ORDER() fixes that problem, and $NEXT() is provided for legacy code from the dark ages.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)