Skip to content

Commit 58aaa5e

Browse files
committed
[Scalar-List-Utils] fix string comparisons with $] to use numeric comparison instead
The fix follows Zefram's suggestion from https://www.nntp.perl.org/group/perl.perl5.porters/2012/05/msg186846.html > On older perls, however, $] had a numeric value that was built up using > floating-point arithmetic, such as 5+0.006+0.000002. This would not > necessarily match the conversion of the complete value from string form > [perl #72210]. You can work around that by explicitly stringifying > $] (which produces a correct string) and having *that* numify (to a > correctly-converted floating point value) for comparison. I cultivate > the habit of always stringifying $] to work around this, regardless of > the threshold where the bug was fixed. So I'd write > > use if "$]" >= 5.014, warnings => "non_unicode";
1 parent 1e1a9b2 commit 58aaa5e

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

cpan/Scalar-List-Utils/t/stack-corruption.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!./perl
22

33
BEGIN {
4-
if ($] eq "5.008009" or $] eq "5.010000" or $] le "5.006002") {
4+
if ("$]" == 5.008009 or "$]" == 5.010000 or "$]" <= 5.006002) {
55
print "1..0 # Skip: known to fail on $]\n";
66
exit 0;
77
}

cpan/Scalar-List-Utils/t/sum.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ SKIP: {
9898
cmp_ok($t, 'gt', 1152921504606846976, 'sum uses IV where it can'); # string comparison because Perl 5.6 does not compare it numerically correctly
9999

100100
SKIP: {
101-
skip "known to fail on $]", 1 if $] le "5.006002";
101+
skip "known to fail on $]", 1 if "$]" <= 5.006002;
102102
$t = sum(1<<60, 1);
103103
cmp_ok($t, '>', 1<<60, 'sum uses IV where it can');
104104
}

cpan/Scalar-List-Utils/t/uniq.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ is_deeply( [ uniqstr qw( 1 1.0 1E0 ) ],
4444
}
4545

4646
SKIP: {
47-
skip 'Perl 5.007003 with utf8::encode is required', 3 if $] lt "5.007003";
47+
skip 'Perl 5.007003 with utf8::encode is required', 3 if "$]" < 5.007003;
4848
my $warnings = "";
4949
local $SIG{__WARN__} = sub { $warnings .= join "", @_ };
5050

@@ -99,7 +99,7 @@ is_deeply( [ uniqint 6.1, 6.2, 6.3 ],
9999
}
100100

101101
SKIP: {
102-
skip('UVs are not reliable on this perl version', 2) unless $] ge "5.008000";
102+
skip('UVs are not reliable on this perl version', 2) unless "$]" >= 5.008000;
103103

104104
my $maxbits = $Config{ivsize} * 8 - 1;
105105

@@ -153,7 +153,7 @@ is( scalar( uniqstr qw( a b c d a b e ) ), 5, 'uniqstr() in scalar context' );
153153
}
154154

155155
SKIP: {
156-
skip('int overload requires perl version 5.8.0', 1) unless $] ge "5.008000";
156+
skip('int overload requires perl version 5.8.0', 1) unless "$]" >= 5.008000;
157157

158158
package Googol;
159159

cpan/Scalar-List-Utils/t/uniqnum.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ SKIP: {
296296
# uniqnum not confused by IV'ified floats
297297
SKIP: {
298298
# This fails on 5.6 and isn't fixable without breaking a lot of other tests
299-
skip 'This perl version gets confused by IVNV dualvars', 1 if $] lt '5.008000';
299+
skip 'This perl version gets confused by IVNV dualvars', 1 if "$]" <= 5.008000;
300300
my @nums = ( 2.1, 2.2, 2.3 );
301301
my $dummy = sprintf "%d", $_ for @nums;
302302

0 commit comments

Comments
 (0)