line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Util::DictOrder; |
2
|
10
|
|
|
10
|
|
51
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
335
|
|
3
|
10
|
|
|
10
|
|
48
|
use warnings qw(FATAL all NONFATAL misc); |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
413
|
|
4
|
10
|
|
|
10
|
|
50
|
use base qw/Exporter/; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
3701
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw(&dict_order &dict_sort); |
7
|
|
|
|
|
|
|
our @EXPORT = @EXPORT_OK; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub dict_order { |
10
|
33
|
|
|
33
|
1
|
48
|
my ($a, $b, $start) = @_; |
11
|
33
|
50
|
|
|
|
71
|
$start = 1 unless defined $start; |
12
|
33
|
|
|
|
|
44
|
my ($result, $i) = (0); |
13
|
33
|
|
33
|
|
|
149
|
for ($i = $start; $i <= $#$a and $i <= $#$b; $i++) { |
14
|
66
|
100
|
66
|
|
|
253
|
if ($a->[$i] =~ /^\d/ and $b->[$i] =~ /^\d/) { |
15
|
33
|
|
|
|
|
52
|
$result = $a->[$i] <=> $b->[$i]; |
16
|
|
|
|
|
|
|
} else { |
17
|
33
|
|
|
|
|
63
|
$result = $a->[$i] cmp $b->[$i]; |
18
|
|
|
|
|
|
|
} |
19
|
66
|
100
|
|
|
|
258
|
return $result unless $result == 0; |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
0
|
return $#$a <=> $#$b; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# a => ['a', 'a'] |
25
|
|
|
|
|
|
|
# q1a => ['q1a', 'q', 1, 'a'] |
26
|
|
|
|
|
|
|
# q11b => ['q11b', 'q', 11, 'b'] |
27
|
|
|
|
|
|
|
sub dict_sort (@) { |
28
|
1
|
|
|
1
|
1
|
4
|
map {$_->[0]} sort {dict_order($a,$b)} map {[$_, split /(\d+)/]} @_; |
|
13
|
|
|
|
|
23
|
|
|
33
|
|
|
|
|
56
|
|
|
13
|
|
|
|
|
60
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
YATT::Util::DictOrder - Dictionary-style ordering and sorting. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use YATT::Util::DictOrder; |
40
|
|
|
|
|
|
|
print join ",", dict_sort qw(q3-1 q3 q10a q1); |
41
|
|
|
|
|
|
|
# prints "q1,q3,q3-1,q10a" |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
print join ",", |
44
|
|
|
|
|
|
|
map {$$_[0]} |
45
|
|
|
|
|
|
|
sort {dict_order($a, $b, 1)} |
46
|
|
|
|
|
|
|
map {[$$_[0], split /(\d+)/, $$_[1]]} |
47
|
|
|
|
|
|
|
[qw(foo q3-1)], |
48
|
|
|
|
|
|
|
[qw(summer q3)], |
49
|
|
|
|
|
|
|
[qw(moe q10a)], |
50
|
|
|
|
|
|
|
[qw(romantic q1)]; |
51
|
|
|
|
|
|
|
# prints "romantic,summer,foo,moe" |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 C |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 C |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
KOBAYASI, Hiroaki (C) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 LICENSE |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or modify |
66
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |