See how I've wrapped $user_id in quotes like "$user_id" to force string context. When the user ID is represented as a number, the internal representation of the number causes rounding because of lost precision.Well, yes, but no. It's true that in rare cases you want to force string context. But if you are going to use $user_id as a number, putting quotes around it isn't going to help you. Sure, you prevent $user_id to become a number, but Perl will happely convert "$user_id" to a number. If you never use $user_id as a number, Perl will not calculate its numeric value, and no rounding will happen. (But be aware of YAML!).
The usual cases where you want for force string context are those operators that do different things depending whether their operands are strings or numbers. And in boolean context.
In reply to Re: "force string context"?
by Abigail-II
in thread "force string context"?
by bronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |