line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sort::SubList; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2019-12-14'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Sort-SubList'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
67394
|
use 5.010001; |
|
1
|
|
|
|
|
14
|
|
9
|
1
|
|
|
1
|
|
7
|
use strict 'subs', 'vars'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
10
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
236
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(sort_sublist); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub sort_sublist { |
16
|
1
|
50
|
|
1
|
1
|
1268
|
my $cmp_sub = shift |
17
|
|
|
|
|
|
|
or die "Please supply comparison routine (first arg)"; |
18
|
1
|
50
|
|
|
|
4
|
my $select_sub = shift |
19
|
|
|
|
|
|
|
or die "Please supply elemnet selection routine (second arg)"; |
20
|
1
|
|
|
|
|
4
|
my @list = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
2
|
my @pos_selected; |
23
|
|
|
|
|
|
|
my @selected; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
ELEM: |
26
|
1
|
|
|
|
|
4
|
for my $i (0..$#_) { |
27
|
8
|
100
|
|
|
|
23
|
{ local $_ = $list[$i]; next ELEM unless $select_sub->($_) } |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
12
|
|
28
|
4
|
|
|
|
|
21
|
push @selected, $list[$i]; |
29
|
4
|
|
|
|
|
7
|
push @pos_selected, $i; |
30
|
|
|
|
|
|
|
} |
31
|
1
|
|
|
|
|
5
|
@selected = sort { $cmp_sub->($a, $b) } @selected; |
|
5
|
|
|
|
|
15
|
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
5
|
for (0..$#pos_selected) { |
34
|
4
|
|
|
|
|
8
|
$list[ $pos_selected[$_] ] = $selected[$_]; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
4
|
@list; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# ABSTRACT: Sort only certain elements in a list, while maintaining the order of the rest |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |