From: Mike Guy Date: Thu, 10 Aug 2000 15:50:54 +0000 (+0100) Subject: Fixes to looking-like-number to keep behaviour as it was in 5.005_03. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0a3ece5567993cdf5de26e22ebce420ba267a0f6;p=p5sagit%2Fp5-mst-13.2.git Fixes to looking-like-number to keep behaviour as it was in 5.005_03. Subject: Re: [ID 20000810.002] $a["1foo"] same as $a[0] Message-Id: p4raw-id: //depot/perl@6583 --- diff --git a/sv.c b/sv.c index 382805f..ab4d6d5 100644 --- a/sv.c +++ b/sv.c @@ -1569,22 +1569,13 @@ Perl_sv_2iv(pTHX_ register SV *sv) goto ret_iv_max; } } - else if (numtype) { - /* The NV may be reconstructed from IV - safe to cache IV, - which may be calculated by atol(). */ - if (SvTYPE(sv) == SVt_PV) - sv_upgrade(sv, SVt_PVIV); - (void)SvIOK_on(sv); - SvIVX(sv) = Atol(SvPVX(sv)); - } - else { /* Not a number. Cache 0. */ - dTHR; - + else { /* The NV may be reconstructed from IV - safe to cache IV, + which may be calculated by atol(). */ if (SvTYPE(sv) < SVt_PVIV) sv_upgrade(sv, SVt_PVIV); (void)SvIOK_on(sv); - SvIVX(sv) = 0; - if (ckWARN(WARN_NUMERIC)) + SvIVX(sv) = Atol(SvPVX(sv)); + if (! numtype && ckWARN(WARN_NUMERIC)) not_a_number(sv); } } diff --git a/t/op/int.t b/t/op/int.t index 6ac0866..bf21002 100755 --- a/t/op/int.t +++ b/t/op/int.t @@ -5,7 +5,7 @@ BEGIN { unshift @INC, '../lib'; } -print "1..6\n"; +print "1..7\n"; # compile time evaluation @@ -28,3 +28,9 @@ print $x == -7 ? "ok 5\n" : "# expected -7, got $x\nnot ok 5\n"; $y = (3/-10)*-10; print $x+$y == 3 && abs($x) < 10 ? "ok 6\n" : "not ok 6\n"; } + +# check bad strings still get converted + +@x = ( 6, 8, 10); +print "not " if $x["1foo"] != 8; +print "ok 7\n";