in reply to Re: Comparing all keys in a hash
in thread Comparing all keys in a hash

Of course I know you're not suppose to rely on hash order but would two hashes with the same keys return in the same order? I would think so but don't know (And don't have time to test) but if it did you could skip the sort. But it probably would be a bad idea.
In the current Perl 5 implementation of hashes, you cannot rely of ordering of keys. You may get two canonically identical hashes, which should appear the same, but compare differently without a sort. If the elements were inserted in different sequences, you can see this.

Try comparing { foo => 1, bar => 5 } with { bar => 5 , foo => 1 }.

See also this thread

Replies are listed 'Best First'.
Re: Re: Re: Comparing all keys in a hash
by shotgunefx (Parson) on Mar 20, 2003 at 19:14 UTC
    Actually this does work for me. I think there is an compiler option SHARE_KEYS that I specified when building Perl that might have something to do with it.(I don't remember seeing it in previous version though)

    Regardless, as I originally stated, it's a bad idea to rely on this ordering.

    -Lee

    "To be civilized is to deny one's nature."