1Sort::Key::Multi(3) User Contributed Perl Documentation Sort::Key::Multi(3)
2
3
4
6 Sort::Key::Multi - simple multi-key sorts
7
9 use Sort::Key::Multi qw(sikeysort);
10 my @data = qw(foo0 foo1 bar34 bar0 bar34 bar33 doz4)
11 my @sisorted = sikeysort { /(\w+)(\d+)/} @data;
12
14 Sort::Key::Multi creates multi-key sorting subroutines and exports them
15 to the caller package.
16
17 The names of the sorters are of the form "xxxkeysort" or
18 "xxxkeysort_inplace", where "xxx" determines the number and types of
19 the keys as follows:
20
21 + "i" indicates an integer key, "u" indicates an unsigned integer
22 key, "n" indicates a numeric key, "s" indicates a string key and
23 "l" indicates a string key that obeys locale order configuration.
24
25 + Type characters can be prefixed by "r" to indicate reverse order.
26
27 + A number following a type character indicates that the key type
28 has to be repeated as many times (for instance "i3" is equivalent
29 to "iii" and "rs2" is equivalent to "rsrs").
30
31 + Underscores ("_") can be freely used between type indicators.
32
33 For instance:
34
35 use Key::Sort::Multi qw(iirskeysort
36 i2rskeysort
37 i_i_rs__keysort
38 i2rs_keysort);
39
40 exports to the caller package fourth identical sorting functions that
41 take two integer keys that are sorted in ascending order and one string
42 key that is sorted in descending order.
43
44 The generated sorters take as first argument a subroutine that is used
45 to extract the keys from the values which are passed inside $_, for
46 example:
47
48 my @data = qw(1.3.foo 1.3.bar 2.3.bar 1.4.bar 1.7.foo);
49 my @s = i2rs_keysort { split /\./, $_ } @data;
50
52 For a more general multi-key sorter generator see Sort::Key::Maker.
53
55 Copyright (C) 2006, 2014 by Salvador FandiƱo <sfandino@yahoo.com>
56
57 This library is free software; you can redistribute it and/or modify it
58 under the same terms as Perl itself, either Perl version 5.8.4 or, at
59 your option, any later version of Perl 5 you may have available.
60
61
62
63perl v5.34.0 2021-07-22 Sort::Key::Multi(3)