in reply to How to sort a hash by its values?

why doesn't this work?
print $_ , "\n" foreach (sort values %x);
Update: My poor wording made this sound like a golf. I'm really confused as to why this doesn't work but take out sort and it appears to

Replies are listed 'Best First'.
Re: Re: How to sort a hash by its values?
by davorg (Chancellor) on Jul 19, 2001 at 20:50 UTC
Re: Re: How to sort a hash by its values?
by dsb (Chaplain) on Jul 19, 2001 at 20:57 UTC
    That particular code won't work because without explicitly comparing the values like '$a <=> $b', the sort function will treat the values as strings and sort based on the first byte rather than its integer value.

    So rather than:

    314 232 82 0
    You get:
    0 232 314 82

    Hope that helps.

    Amel - f.k.a. - kel