Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Sorting an array of strings by number

by jeroenes (Priest)
on Oct 01, 2001 at 16:05 UTC ( #115835=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $padded=sprintf("%08.3f",39.452);
    
  2. or download this
    while (<>){
      split /:/;
      $_[0]=sprintf("%08.3f", $_[0]);
      push @data, join ":", @_;
    }
    
  3. or download this
        sort{ $a <=> $b} @numbers;
    
  4. or download this
    sort{extract( $a ) <=> extract( $b )} @lines;
    
    ...
      split /:/, $a;
      $_[0];
    }
    
  5. or download this
    my %hash;
    while(<>){
    ...
      $hash{ $key } = $data;
    }
    print "Sorted!:\n\n", join "|", sort {$a <=> $b} keys %hash;
    
  6. or download this
    $key .= ':001' if defined $hash{$key};
    $key++ while defined $hash{$key};
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2015-07-05 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls