line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Scalar::Cmp; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2018-12-06'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
66516
|
use 5.010001; |
|
1
|
|
|
|
|
12
|
|
7
|
1
|
|
|
1
|
|
13
|
use strict 'subs', 'vars'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw(looks_like_number); |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
477
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
15
|
|
|
|
|
|
|
cmp_scalar |
16
|
|
|
|
|
|
|
cmpnum_scalar |
17
|
|
|
|
|
|
|
cmpstrornum_scalar |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub cmp_scalar { |
21
|
18
|
|
|
18
|
1
|
1278
|
my ($d1, $d2) = @_; |
22
|
|
|
|
|
|
|
|
23
|
18
|
|
|
|
|
31
|
my $def1 = defined $d1; |
24
|
18
|
|
|
|
|
25
|
my $def2 = defined $d2; |
25
|
18
|
100
|
100
|
|
|
112
|
if ( $def1 && !$def2) { return 1 } |
|
2
|
100
|
100
|
|
|
9
|
|
|
|
100
|
66
|
|
|
|
|
26
|
2
|
|
|
|
|
9
|
elsif (!$def1 && $def2) { return -1 } |
27
|
1
|
|
|
|
|
5
|
elsif (!$def1 && !$def2) { return 0 } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# so both are defined ... |
30
|
|
|
|
|
|
|
|
31
|
13
|
|
|
|
|
20
|
my $ref1 = ref $d1; |
32
|
13
|
|
|
|
|
21
|
my $ref2 = ref $d2; |
33
|
13
|
100
|
100
|
|
|
48
|
if ($ref1 xor $ref2) { return 2 } |
|
3
|
100
|
|
|
|
11
|
|
34
|
5
|
100
|
|
|
|
40
|
elsif ($ref1) { return $d1 == $d2 ? 0 : 2 } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# so both are not references ... |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
|
|
18
|
$d1 cmp $d2; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub cmpnum_scalar { |
42
|
16
|
|
|
16
|
1
|
2731
|
my ($d1, $d2) = @_; |
43
|
|
|
|
|
|
|
|
44
|
16
|
|
|
|
|
25
|
my $def1 = defined $d1; |
45
|
16
|
|
|
|
|
23
|
my $def2 = defined $d2; |
46
|
16
|
100
|
100
|
|
|
103
|
if ( $def1 && !$def2) { return 1 } |
|
2
|
100
|
100
|
|
|
9
|
|
|
|
100
|
66
|
|
|
|
|
47
|
2
|
|
|
|
|
8
|
elsif (!$def1 && $def2) { return -1 } |
48
|
1
|
|
|
|
|
6
|
elsif (!$def1 && !$def2) { return 0 } |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# so both are defined ... |
51
|
|
|
|
|
|
|
|
52
|
11
|
|
|
|
|
20
|
my $ref1 = ref $d1; |
53
|
11
|
|
|
|
|
18
|
my $ref2 = ref $d2; |
54
|
11
|
100
|
100
|
|
|
40
|
if ($ref1 xor $ref2) { return 2 } |
|
3
|
100
|
|
|
|
12
|
|
55
|
5
|
100
|
|
|
|
33
|
elsif ($ref1) { return $d1 == $d2 ? 0 : 2} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# so both are not references ... |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
17
|
$d1 <=> $d2; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub cmpstrornum_scalar { |
63
|
18
|
|
|
18
|
1
|
2753
|
my ($d1, $d2) = @_; |
64
|
|
|
|
|
|
|
|
65
|
18
|
|
|
|
|
28
|
my $def1 = defined $d1; |
66
|
18
|
|
|
|
|
27
|
my $def2 = defined $d2; |
67
|
18
|
100
|
100
|
|
|
111
|
if ( $def1 && !$def2) { return 1 } |
|
2
|
100
|
100
|
|
|
9
|
|
|
|
100
|
66
|
|
|
|
|
68
|
2
|
|
|
|
|
9
|
elsif (!$def1 && $def2) { return -1 } |
69
|
1
|
|
|
|
|
5
|
elsif (!$def1 && !$def2) { return 0 } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# so both are defined ... |
72
|
|
|
|
|
|
|
|
73
|
13
|
|
|
|
|
23
|
my $ref1 = ref $d1; |
74
|
13
|
|
|
|
|
18
|
my $ref2 = ref $d2; |
75
|
13
|
100
|
100
|
|
|
72
|
if ($ref1 xor $ref2) { return 2 } |
|
3
|
100
|
|
|
|
14
|
|
76
|
5
|
100
|
|
|
|
30
|
elsif ($ref1) { return $d1 == $d2 ? 0 : 2 } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# so both are not references ... |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
18
|
my $llnum1 = looks_like_number($d1); |
81
|
5
|
|
|
|
|
10
|
my $llnum2 = looks_like_number($d2); |
82
|
5
|
100
|
66
|
|
|
50
|
$llnum1 && $llnum2 ? ($d1 <=> $d2) : ($d1 cmp $d2); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
# ABSTRACT: Compare two scalars |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |