Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: All Calculations Done with One Variable Give Integer Answers

by syphilis (Chancellor)
on Sep 23, 2013 at 23:38 UTC ( #1055406=note: print w/replies, xml ) Need Help??

in reply to All Calculations Done with One Variable Give Integer Answers


Could you, at some point in your code where $gap is producing this "integer" behaviour, insert the following piece of code:
use Devel::Peek; Dump($gap);
and then provide us with the output of that Dump().

$gap = "$gap.00";

I suspect that you'll get the same change in behaviour by doing simply:
$gap = "$gap";

Replies are listed 'Best First'.
Re^2: All Calculations Done with One Variable Give Integer Answers
by HalNineThousand (Beadle) on Sep 24, 2013 at 06:09 UTC
    I'm not clear whether I should try dumping after I get $gap (now $mins in the code I've added) from the module or before that. But you are right. Just using quotations is enough to make it change behavior. With that known, can you tell me just what is happening and if that's a reliable hack?

      The line $mins = "$mins.00"; turns the Math::BigInt object into a standard Perl scalar. If you inspect $mins using Data::Dumper before and after $mins = "$mins.00"; you get:

      $VAR1 = bless( { 'value' => [ 43200 ], 'sign' => '+' }, 'Math::BigInt' ); $VAR1 = '43200.00';

      So (with hindsight!) had you used Data::Dumper as a first step to see what's going on, you would have been told immediately. But this is only with hindsight...

        Perhaps this time it is "Hindsight", but next time it could be "Lesson Learned", "Experience", "Defensive Programming", or, Monastary forbid, a "Good Engineering Practice".

        This incident has added a rather large stone on the scale which was already precariously close to tipping in favor of switching to the use of Data::Dumper over my rather obsolete and unrobust homespun debug module from longer ago than I'd care to admit.

        Thanks for the analysis and summary. Thanks to the OP for posting -- and clarifying -- the problem.

        Yes, with hindsight! Funny how often we get the answer and then realize that the right 1st step would have solved it. Thank you!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055406]
[choroba]: but gurus say they in fact happen left to right, but we understand them wrongly
[marioroy]: bad gurus :)
[choroba]: also, &> redirects both at the same time
[marioroy]: erix are you using csh
Discipulus uh the link was for cmd.exe the bash one
[marioroy]: If yes, for redirection to work, one might do the following
[marioroy]: `bash -c "clang --version 2>/dev/null"`
[choroba]: Sane people don't use csh
[marioroy]: the 1>&2 will work, not shown
[marioroy]: sorry, did not know which if cmd.exe or unix (bash)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-03-23 08:21 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (284 votes). Check out past polls.