Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I was expecting to get (-8, -5, 0, 0, 1, 2, 3, 4, 6, 7, 9), but instead I got (1, 2, 3, 4, 5, 6, 7, 8, 9). Any thoughts?#!c:\perl\bin use strict; use warnings; my @data = (1,-5,0,-8,2,0,4,7,3,6,9); @data = sortData(@data, "Integer"); sub sortData { my @data = $_[0]..$_[scalar(@_)-2]; my $dataType = $_[scalar(@_)-1]; if($dataType eq 'Integer' || $dataType eq 'Float') { sort {$a <=> $b} @data; } else { sort @data; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A problem sorting numbers with sort()
by kvale (Monsignor) on Mar 16, 2004 at 23:22 UTC | |
|
Re: A problem sorting numbers with sort()
by Koosemose (Pilgrim) on Mar 16, 2004 at 23:28 UTC | |
|
Re: A problem sorting numbers with sort()
by borisz (Canon) on Mar 16, 2004 at 23:32 UTC | |
|
Re: A problem sorting numbers with sort()
by Anomynous Monk (Scribe) on Mar 17, 2004 at 04:06 UTC | |
|
Re: A problem sorting numbers with sort()
by Anonymous Monk on Mar 16, 2004 at 23:57 UTC |