in reply to New to Perl, getting funny results when sorting an Array

Here's one mistake:

@hwall = keys %average; @hwall = sort (%average);

What you probably meant was:

@hwall = keys %average; @hwall = sort { $average{$a} <=> $average{$b} } @hwall;

...at least that is if I understand your intent. I may have misunderstood it, making my solution in error, but the second line I pointed out definately is a bug. ;)


Dave

Replies are listed 'Best First'.
Re^2: New to Perl, getting funny results when sorting an Array
by eibwen (Friar) on Apr 13, 2005 at 07:08 UTC
    Or if you prefer:

    @hwall = sort { $average{$a} <=> $average{$b} } keys %average;

    I noticed you enabled warnings with the -w switch, but don't forget to use strict as well. If you're having trouble making sense of the error messages, try use diagnostics.