At 10:54 AM -0800 7/14/06, [EMAIL PROTECTED] wrote:
>I have been tasked with converting all of the network utilities I've written
>over the years in MUMPS into a language likely to be known by more people.
>Most of it will be converted to Perl.  So far the conversion hasn't presented
>to many difficulties but there is one construct for which I have not been able
>to derive a close equivalent.  To wit:
>
>MUMPS arrays use alphanumeric indicies with a defined collating order.  Numeric
>subscripts collate first, in numeric order, followed by string subscripts in
>ASCII order.  Thus, an array with the following indicies would collate in this
>order: -2,-1,0,1,2,9,100,101.5,A,E,H,a,c,z etc.  MUMPS arrays are also sparse
>arrays and are multidimensional.  However, for this question, it is okay to
>assume an array with only one dimension.
>
>The MUMPS language provides a function, called $ORDER, which takes an argument
>and returns the next index that exists in the array that would come after the
>supplied argument (a 2nd argument can be used to cause the function to return
>the previous index instead of the next index).  For example, given an array
>with the index values given above, if I asked for the next index after 0, I
>would get 1; the next index after 50 would return 100; the next index after "Z"
>would return "a"; etc.
>
>My question: is there any way to approach similar functionality in Perl?  Any
>non-numeric arrays in my code are being converted to Perl hashes.  I can
>retrieve the value of a specific key, and I can use a for loop to go through
>every key/value pair but, is there any way of doing something similar to $ORDER
>without have to scan the entire hash?  Also, is there any defined order in
>which a hash is stored?

No, I don't think you can depend on the order of hash storage, though
there are various ordered hash modules available.  You might try a a
tied hash implemented via a lookaside hash that keeps track of the next
and previous keys for each key in the primary hash.

Have you looked at the MUMPS to Perl translator at:

http://search.cpan.org/~smueller/Language-Mumps-1.07/Mumps.pm

Even if the code it generates is not something you want to use, you
might get ideas for how to do things.

Whatever you do, I would recommend borrowing from what's out there,
and there is a lot of it.  Go to <http://search.cpan.org> and try
some likely searches such as "sparse" or "ordered hash."
-- 
________________________________________
Craig A. Berry
mailto:[EMAIL PROTECTED]

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Reply via email to