Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Numeric sorting WITHOUT <=>

by AnomalousMonk (Chancellor)
on Oct 09, 2012 at 22:03 UTC ( #998091=note: print w/replies, xml ) Need Help??

in reply to Numeric sorting WITHOUT <=>

Why, oh why would you want to do numeric sorting without the numeric comparison operator? Interview question? Failure of communication? XY Problem? In any event, maybe something like this:

>perl -wMstrict -le "my %jetsons = ( 7 => 'Judy', 10 => 'Jane', 11 => 'George', 2 => 'Elroy', 100=> 'Rosey', 1 => 'Astro', 19 => 'Mr. Spacely', 22 => 'Mr. Cogswell' ); ;; my @sorted = sort non_spaceship keys %jetsons; print qq{@sorted}; ;; sub non_spaceship { return $a < $b ? -1 : $a > $b ? 1 : 0 } " 1 2 7 10 11 19 22 100

Replies are listed 'Best First'.
Re^2: Numeric sorting WITHOUT <=>
by ria1328 (Initiate) on Oct 09, 2012 at 22:22 UTC

    Not my idea, its for a class. That might work but he hinted at using nested loops to numerically sort the keys.

      Ah: "Give a man a fish and he will eat for a day. Tell a man to beat the fish to death with a baseball bat and he will happily use a fishing hook and line for all the rest of his days."

      If he's talking about nested loops, then you're probably not supposed to use the Perl sort function at all, but instead to implement a sorting algorithm from scratch. Hopefully, then, the class has already covered at least one sorting algorithm for you to implement. If not, google can provide explanations of how several sorting algorithms work, then it's just a matter of translating the algorithm's description into Perl code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998091]
[corenth]: each reference was to a fairly small scaler.
[corenth]: I mean, array of scalers. usually triples.
[Cosmic37]: there is a FANN discussion group but seems to have gone quiet... http://leenissen. dk/fann/forum/ viewforum.php?f=18 &sid=1afc1fb3fa1a3 7f52b03e40d05cdaaa 3
[corenth]: Where are all the FANN fans?
[Cosmic37]: ok it went quiet because it moved - its actually quite active... https://sourceforg discussion/
[Cosmic37]: Therefore they are on sourceforge

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-02-20 18:33 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (274 votes). Check out past polls.