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