* Viljo Marrandi <[EMAIL PROTECTED]> [2002-06-06 09:48]:
> I know there are many tricks in TT that make life much easier, but is
> there a decent way to change order of keys in hash? It seems to me
> that perl doesn't care how I add these values to hash and it prints
> them out in weird order too.

Perl stores hashes in an order that facilitates fast lookup, which the
whole purpose of using hashes.  If you need them in a particular order,
look into Tie::IxHash, which allows for ordered hashes, or consider
using an array.  The hash:

%hash = (
    'oigus' => 'foo',
    'pohipakett' => 'foo2',
    'reisitorge' => 'bar',
    'pagas' => 'asd',
)

Can be expressed as the array:

@array = (
    'oigus' => 'foo',
    'pohipakett' => 'foo2',
    'reisitorge' => 'bar',
    'pagas' => 'asd',
)

and values retrieved in order.

(darren)

--
With or without religion, good people can behave well and bad people
can do evil; but for good people to do evil -- that takes religion.
    -- Steven Winberg


Reply via email to