Data-Sorting

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

      @ordered = sorted_by( [ -compare => 'numeric' ], @numbers );
      @ordered = sort_function( -compare => 'numeric' )->( @numbers );
      @ordered = sorted_array( @numbers, -compare => 'numeric' );
      sort_array( @numbers, -compare => 'numeric' );
  
      # You can sort by the results of a function to be called on each item
      sort_array( @numbers, -compare => 'numeric', sub { $_[0] % 16 } );
      # @numbers now contains 64, 18, 5, 23, 42, 91, 156
  
      # For arrays of datastructures, pass in keys to extract for sorting
      @records = ( 
        { 'rec_id'=>3, 'name'=>{'first'=>'Bob', 'last'=>'Macy'} },
        { 'rec_id'=>1, 'name'=>{'first'=>'Sue', 'last'=>'Jones'} },
        { 'rec_id'=>2, 'name'=>{'first'=>'Al',  'last'=>'Jones' } },
      );
      @ordered = sorted_array( @records, 'rec_id' );

      # For nested data structures, pass an array of keys to fetch
      @ordered = sorted_array( @records, ['name','first'] );

      # Pass multiple sort keys for multiple-level sorts
      @ordered = sorted_array( @records, ['name','last'], ['name','first'] );
  
      # Any selected sort options are applied to all subsequent sort keys
      @ordered = sorted_array( @records, 
                    -order => 'reverse', ['name','last'], ['name','first'] );
  
      # Options specified within a hash-ref apply only to that key
      @ordered = sorted_array( @records, 
                    { order=>'reverse', sortkey=>['name','last'] }, 
                    ['name','first'] );
  
      # Locale support is available if you have Perl 5.004 or later and POSIX
      POSIX::setlocale( POSIX::LC_COLLATE(), 'en_US' );
      POSIX::setlocale( POSIX::LC_CTYPE(), 'en_US' );
      @ordered = sorted_array( @records, 
                     -compare=>'locale', ['name','last'], ['name','first'] );

STATUS AND SUPPORT
    This release of Data::Sorting is intended for public review and
    feedback.

      Name            DSLIP  Description
      --------------  -----  ---------------------------------------------
      Data::
      ::Sorting       bdpfp  Multi-key sort using function results

    Further information and support for this module is available at
    www.evoscript.org.

    Please report bugs or other problems to <bugs@evoscript.com>.

BUGS AND TO DO
    The following issues have been noted for future improvements:

    Convert more types of comparisons to packed-default sorts for speed.

    Further investigate the current status of the Sort::Records module.

    Add a comparator function for an alpha-numeric-spans sorting model like
    Sort::Naturally.

    Interface to Sort::PolySort for alternate comparator styles, like "name"
    and "usdate".

    For non-scalar values, compare referents along the lines of
    Ref::cmpref().

    Provide better handling for nested sorts; perhaps throw an exception
    from the inner instance to the outer, catch and set $PreCalculate, then
    go back into the loop?

    Replace dynamic scoping with object instances for thread safety. May not
    be necessary given changes in threading models.

CREDITS AND COPYRIGHT
  Developed By

      M. Simon Cavalletto, simonm@cavalletto.org
      Evolution Softworks, www.evoscript.org

  Copyright

    Copyright 2003 Matthew Cavalletto.

    Portions copyright 1996, 1997, 1998, 1999 Evolution Online Systems, Inc.

  License

    You may use, modify, and distribute this software under the same terms
    as Perl.



( run in 1.051 second using v1.01-cache-2.11-cpan-56fb94df46f )