in reply to order of hash

Some want to delve and understand (for many good reasons) the internals of how Perl implements the hash. As users (for me, too many interests besides the above), some want to know whether the ordering of the hash is consistent. As a user, I would say that I can imagine that the hash order would be the same for the same data and all other things being equal, but I would never try to depend on that ordering. After all, I'm looking up by key, not in order.. a nice foreach works well (I can always sort the keys if I need to).

Replies are listed 'Best First'.
Re: Re: order of hash
by hardburn (Abbot) on Nov 04, 2003 at 15:06 UTC

    As many other posters pointed out, as of perl 5.8.1, the hash order will no longer be the same between runs. Before that, you could assume that the order would be the same on the same version of perl and get away with it.

    So if you're depending on keys %hash to have consistant output, you better have a sort in front of it.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated