guha has asked for the wisdom of the Perl Monks concerning the following question:
Today I ran into a puzzler regarding how perl interprets a scalar.
The problem cropped up in a program that basically gets a large string from a database and then using substr extracts substrings.
Some of these substrings are ASCII representations of floats, ie 0.123 or 21.654.
The problem cropped up in a program that basically gets a large string from a database and then using substr extracts substrings.
Some of these substrings are ASCII representations of floats, ie 0.123 or 21.654.
The odd thing is that when these values are used for calculations they will behave as if they were integers. For example multiplying a scalar, say $v2, containing 21.654 with 2 yields the result 42!!
Trying to duplicate the problem with a small testscript failed, that is it works as expected.
When checking debug printouts from the original program with a hex editor no strange/unexpected characters are found.
Any ideas someone ??
---
It's unfair to be an expert.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 0.123, float or integer
by derby (Abbot) on Feb 05, 2002 at 23:22 UTC | |
by guha (Priest) on Feb 06, 2002 at 10:22 UTC | |
by jmcnamara (Monsignor) on Feb 06, 2002 at 10:57 UTC | |
by guha (Priest) on Feb 05, 2002 at 23:55 UTC | |
Re: 0.123, float or integer
by VSarkiss (Monsignor) on Feb 05, 2002 at 23:48 UTC | |
Re: 0.123, float or integer
by chipmunk (Parson) on Feb 06, 2002 at 05:56 UTC | |
Re: 0.123, float or integer
by guha (Priest) on Feb 06, 2002 at 21:42 UTC |
Back to
Seekers of Perl Wisdom