Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 exploiting the Monastery: (6)
As of 2014-11-01 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (228 votes), past polls