File Coverage

blib/lib/Math/Vector/SortIndexes.pm
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 0 2 0.0
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Math::Vector::SortIndexes;
2              
3             $VERSION = 0.02;
4             @EXPORT_OK = qw(sort_indexes_descending sort_indexes_ascending);
5 1     1   24273 use base 'Exporter';
  1         2  
  1         657  
6              
7             sub sort_indexes_descending {
8 1     1 0 7 (sort { $_[$b] <=> $_[$a] } 0..$#_);
  5         10  
9             }
10              
11             sub sort_indexes_ascending {
12 1     1 0 21 (sort { $_[$a] <=> $_[$b] } 0..$#_);
  5         27  
13             }
14              
15             =head1 NAME
16              
17             Math::Vector::SortIndexes - Sort the indices of a numeric vector
18              
19             =head1 SYNOPSIS
20              
21             use Math::Vector::SortIndexes qw(sort_indexes_descending
22             sort_indexes_ascending);
23            
24             @vector = qw(44 22 33 11);
25             @indexes1 = sort_indexes_ascending @vector;
26             @indexes2 = sort_indexes_descending @vector;
27              
28             print "@indexes1\n"; # Prints 3 1 2 0
29             print "@indexes2\n"; # Prints 0 2 1 3
30              
31             =head1 DESCRIPTION
32              
33             This module allows you to find the sort the indices of a numeric vector.
34             The subroutine names explain themselves: sort_indexes_ascending and
35             sort_indexes_descending. Import them and use them as you see fit.
36              
37             =head1 AUTHORS
38              
39             David James
40              
41             =head1 SEE ALSO
42              
43             L
44              
45             =head1 LICENSE
46              
47             Copyright (c) 2002 David James
48             All rights reserved.
49             This program is free software; you can redistribute it and/or
50             modify it under the same terms as Perl itself.
51            
52             =cut