in reply to Re^2: Getting different results with $var++ and $var += 1
in thread Getting different results with $var++ and $var += 1

I didn't suggest in anyway you post an enormous program here.

What I suggest is that you reduce your code to a minimal program such that it 1) runs, and 2) shows your problem.

Under what conditions can I take a string "110.98" and not be able to use it in numeric context? I thought the answer was "under no conditions ever for any reason under any version of Perl" but clearly I'm wrong.
Oh, no, you are right. If you have a string "110.98", you will be able to use it in numeric context. The problem however is that you may very well have some else than a string.

But since we don't know where the thing you have is coming from, we don't know, do we? And I don't like the game of "I've problem. I only half describe it. Now guess what's going on". If I want to play situation puzzles, I'll go to rec.puzzles.

  • Comment on Re^3: Getting different results with $var++ and $var += 1

Replies are listed 'Best First'.
Re^4: Getting different results with $var++ and $var += 1
by splicer (Novice) on Dec 04, 2008 at 01:24 UTC

    It's cheating because I've already got the answer (in part because you identified the problem) but this had nothing at all to do with the values being generated in the other objects. That I used Math::BigInt in the module (and didn't need it except for in one place) was the problem. So having arrived at the problem, the test case is pretty easy:

    #!/usr/bin/perl use Math::BigInt ':constant'; $discount = 15; $price = "109.98"; print $discount * $price; exit();

    Results NaN unless the use statement is commented out. Then it results in 1649.7;

    I'm guessing the problem is that Math::BigInt is converting all numeric constants to Math::BigInt objects, without checking to see that the numeric constant is an integer or not. Since "109.98" is not an integer, Math::BigInt claims it isn't a number. I'm too ignorant to know whether that is by design or even whether that's really what's happening, but it is my guess.