in reply to Perl 5 numeric type and simplifications

Hello pango and welcome to the monastery and to the wonderful world of Perl!

You already got the correct answer, so apart my welcome, I only want to comment:

> I am only interested because I find this an easy way to remove trailing decimal zeroes, and if I can get away with not using sprintf then that would be great.

you dont pay CPU cycles nor characters in your program, do you? So it is better to embrace the more idiomatic style you can, without relying on edge cases to accomplish simple tasks as the precision of a number. One of our wise brothers has in their signature: Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond and even if in Perl there are many way to get the job done I suggest you to write your programs in the clearest form you can get.

Another great motto goes like: Being debugging twice harder than programming, dont program at your best as you dont be able to debug it, by definition

Imagine a weird bug in your 5k lines of perl code spread among different modules, a bug due to a weak assumption on perl rounding beahviour... good luck :)

Explore edge cases, try everything, but when you write something intended to be usable and durable choose the plainest way.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Perl 5 numeric type and simplifications
by Bod (Parson) on May 05, 2021 at 21:02 UTC
    Imagine a weird bug in your 5k lines of perl code spread among different modules...

    I have experienced this kind of bug, or perhaps strange behaviour would be a better term, very recently. In the past I have almost always passed the current user to the database to do the figuring out what to do. But as now all code is being written with Template thanks to the wisdom and good influence of the Monastery, more recently I have wanted the Template to do the work. I couldn't figure out why this wasn't working:

    [% IF user.idUser == current_user %]<input type="button" onClick="doSo +mething();">[% END %]
    Until I printed out current_user from within Template to find it was left padded to 8 digits! MySQL queries treat 255 = 00000255 as true whereas Template treats [% 255 == 00000255 %] as false! I got around the issue by adding zero to the current user before passing it to the Template. I have no idea why the user is calculated and padded this way but too much other code relies on them that I dare not attempt to change this.