• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

t/H28-Dec-2001-236204

ArrayOfArrays.pmH A D28-Dec-200110.1 KiB279153

ChangesH A D25-Dec-2001168 74

MANIFESTH A D28-Dec-2001145 1211

Makefile.PLH A D25-Dec-2001417 2114

READMEH A D28-Dec-20014.1 KiB8872

README

1SYNOPSIS
2      use Sort::ArrayOfArrays;
3      my $sort = Sort::ArrayOfArrays->new({
4        results => [
5          [1 .. 10],
6          [10 .. 1],
7        ],
8        sort_column => -1,
9      });
10      my $sorted = $sort->sort_it;
11
12      # several examples are in the test scripts that came with the package in the t/ directory
13
14DESCRIPTION
15    Sort::ArrayOfArrays was written to sort an arbitrary array of arrays, in
16    powerful, different ways.
17
18PROPERTIES
19    Any of the properties below can be set in your object. This can easily
20    be done by passing a hash ref to new. header_row => set to 1 if you have
21    a header row in $self->{results}
22
23    sort_code => how to sort on each column, can be a code ref - a code ref
24    that gets run through sort (sorry, currently no multi-column sort of
25    code ref) a hash ref - the key is the column number the value is
26    described below, like sort_code => { 0 => 'aa', 2 => 'rd', 4 => 'nd', }
27    an array ref - a list of values as described below, where each position
28    corresponds to the respective column sort_code => [ 'aa', 'la', 'da', ]
29    the sort code values (when not a code ref) are two digits,
30
31      the first digit possibilities are
32        a - alphabetical sort
33        n - numerical sort
34        r - regex sort, where $1 is what gets sorted on, like
35            /<!--stuff-->(.+?)<!--end of stuff-->/
36            use a qr if you need to use switches, like
37            sort_code => {
38              0 => 'ra',
39            },
40            sort_method_regex => {
41              qr/<!--stuff-->(.+?)<!--end of stuff-->/i,
42            }
43            sort_method_regex is a hash ref contain where the key is the column and the value is the regex
44        l - an instance of the regex type, where this regex qr@<a\s+href[^>]+?>(.+?)</a>@i attempts to match a link,
45            if you wanted to match the href, you would have to use the appropriate regex
46
47      the second digit possibilities are
48        a - ascending
49        d - decending
50
51      defaults - the beginning default is 'aa', which is an alphabetical ascending sort, I keep this default if I find a value
52                 in the respective column that contains something that is not "a number", defined by this regex
53                 /[^0-9.\-+ ]/.
54                 If I find a value in the respective column that is only "a number", defined by this regex /^[0-9.\-+]+$/, I use
55                 'na', which is a numerical ascending sort
56
57                 Note that the defaults are problematic, in that I have to look through values, performing regexes.  I stop
58                 as soon as I can, which in my experience is usually after just a value or two, but if this is not acceptable,
59                 or if you would like to perform searches in a way contrary to the default, you need to set a value yourself
60
61      dates - initially I started to write different sort for each date format, but found it much better to do something like
62              <!--1009411647-->December 26, and then just do a 'aa'.  The epoch time in the date will do a nice ascii sort,
63              and not appear in any html.  If this is not acceptable, you can always use a code_ref and sort however you like.
64              You likely want to sprintf out to ten digits just so old nine digit stuff will ascii sort properly
65
66    sort_method_regex => used in conjunction with sort_method of type regex
67    (see above) sort_column => a zero based, column delimited, list of
68    columns you would like to sort on, where a - means to reverse the sort
69    for example, '0' means to sort on the zeroeth column '3,-1,-0', means to
70    try and sort on the third column, then (if the values from both columns
71    are equal), sort on first column in reverse order, then (if the values
72    all above colulmns are equal), sort on the zeroeth column in reverse
73    order,
74
75  EXPORT_OK
76
77    sort_it
78
79AUTHOR
80    Earl Cahill <cpan@spack.net>
81
82THANKS
83    Thanks to Paul T Seamons <paul@seamons.com> for the idea of a nice,
84    simple two letter code for sort definitions, 'aa', 'nd' and the like. It
85    made it pretty easy to add the regex type. It was also Paul's idea to
86    use <!--1234567890--> for time sorts, which saved oh, so many headaches.
87
88