Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
The stupid question is the question not asked
 
PerlMonks  

Re: Numeric sorting WITHOUT <=>

by jandrew (Hermit)
on Oct 09, 2012 at 22:53 UTC ( #998098=note: print w/ replies, xml ) Need Help??


in reply to Numeric sorting WITHOUT <=>

I think an insertion sort using splice might work

Homework Spoiler -
use Modern::Perl; use Smart::Comments; my %jetsons = ( 7 => 'Judy', 10 => 'Jane', 11 => 'George', 2 => 'Elroy', 100=> 'Rosey', 1 => 'Astro', 19 => 'Mr. Spacely', 22 => 'Mr. Cogswell'); my @result = (); for my $key ( keys %jetsons ){ my $x = 0; CHECKLIST: for my $value ( @result ){ if( $value > $key ){ last CHECKLIST; }else{ $x++; } } splice( @result, $x, 0, $key ); } ### @result

Returns

### @result: [ ### 1, ### 2, ### 7, ### 10, ### 11, ### 19, ### 22, ### 100 ### ]


Comment on Re: Numeric sorting WITHOUT <=>
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998098]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-04-19 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls