in reply to Negative number sorting?

Your array contains but a single element, and that element is an anymonous array (created with square brackets --- perhaps that is a typo when posting your code?). Use parentheses for ordinary list construction and remember that sort() does not sort in-place but instead returns the sorted list:

my @array = ( -15, 991, -9, 980, 1, 911, 281, 1299, 870, 1205, 1, 1 ); @array = sort { $a <=> $b } @array; print "@array\n"; __END__ -15 -9 1 1 1 281 870 911 980 991 1205 1299

Replies are listed 'Best First'.
Re: Re: Negative number sorting?
by Ineffectual (Scribe) on Dec 29, 2001 at 01:39 UTC
    Ahh, I understand. My problem was with misunderstanding GD::Graph, not the sort. I was using square brackets because that made the GD::Graph module show up correctly, but the sort wouldn't work correctly. Now using "( )" and \@array, which causes it to show up correctly.

    Is there a way to remove duplicate values using sort or would I have to do a loop to remove them?

    Thanks.
    Ineffectual