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

Re: RFC: I rewrote a custom sort function, but not sure if it is the best way.

by roboticus (Chancellor)
on Mar 03, 2013 at 02:13 UTC ( #1021481=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # When sorting lists of files, I want the index file to always come fi
    +rst.
    if ($c =~ /^index\./) {
    ...
    elsif ($d =~ /^index\./) {
        return 1;
    }
    
  2. or download this
    $ perl PM1021473_3_unstable.pl
    index.0001 afile      article    -1
    index.0001 index.0005 article    -1
    index.9999 index.0005 article    -1
    
  3. or download this
    #!/usr/bin/perl
    #
    ...
    index.0001 afile      article
    index.0001 index.0005 article
    index.9999 index.0005 article
    
  4. or download this
    sub my_sort_article {
      my ($c,$d,$type) = @_;
    ...
      }
      return $c cmp $d;
    }
    
  5. or download this
    sub split_out_leading_number {
        my $s = shift;
    ...
    
        die "split_out_leading_number received bogus input '$s'!\n";
    }
    
  6. or download this
    sub my_sort_article {
      my ($c,$d,$type) = @_;
    ...
        $c cmp $d;
      }
    }
    
  7. or download this
    my @list = ( qw( apple Alpha aLBAtross aLbAcOre etc... ) );
    my @result = sort {uc($a) cmp uc($b)} @original;
    
  8. or download this
    my @list = (
       [qw( APPLE     apple )],
    ...
       [qw( ALBACORE  aLbAcOrE)],
       etc...
    );
    
  9. or download this
    my @result = sort { $a->[0] cmp $b->[0] } @list;
    
  10. or download this
    my @list = (
       [qw( ALBACORE  aLbAcOrE)],
    ...
       [qw( APPLE     apple )],
       etc...
    );
    
  11. or download this
    my @list = ( qw( apple Alpha aLBAtross aLbAcOre etc... ) );
    
    ...
    
    # Now convert the resulting list back into (aLbAcOrE aLBAtross...) for
    +mat:
    @result = map { $_->[1] } @result;
    
  12. or download this
    my @list = ( qw( apple Alpha aLBAtross aLbAcOre etc... ) );
    my @result = map {$_->[1] }              #     .sgnirts desacreppu eht
    + lla tou pirts #
                 sort {$a->[0] cmp $b->[0]}  #  neht dna ,sgnirts desacrep
    +pu eht no tros #
                 map { [ uc($_), $_ ] }      # ,gnirts eht fo noisrev desa
    +creppu eht dda #
                 @list;                      #                            
    + ,tsil a neviG #
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2015-07-30 01:17 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 (269 votes), past polls