develooper Front page | perl.perl5.porters | Postings from December 2021

Re: No implicit coercion?

Thread Previous | Thread Next
Felipe Gasper
December 27, 2021 19:03
Re: No implicit coercion?
Message ID:

> On Dec 27, 2021, at 14:00, Ovid <> wrote:
> On Monday, 27 December 2021, 19:43:02 CET, Felipe Gasper <> wrote:
>> IMO a “stricter” mode that refuses to do “nonsensical” things like numeric operations on 
>> non- numeric SVs, scalar ops on references, etc. would be one of the most helpful features
>> Perl could add. (Magic notwithstanding, of course.)
>> We all know Perl “happily confuses” numbers and numeric strings, but other cases seem like
>> places where the language could (fairly?) readily assist with bug-hunting.
>> Is there a list anywhere of such behaviours?
> Another example is JSON:
>     {value:"0"}
> If someone sends something as a string and I'm expecting a number, I can only guess if "0" is supposed to be the string "0", the number zero, or "false".
> Most of the time the Perl code does the right thing, until it doesn't. And that can cause weird error far away from where the parsing occurs.
> (Yes, I'm aware of the new booleans for Perl:

For “numeric strings” like this I’m not sure it’s as straightforward that a failure should happen.

The recent discussions concerning IOK, IOKp, et al. *may* make it more feasible to fail in these cases, but IMO it would make more sense to solve the less-murky cases first.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About