Front page | perl.perl5.porters |
Postings from December 2021
No implicit coercion?
Thread Next
From:
Ovid via perl5-porters
Date:
December 27, 2021 18:35
Subject:
No implicit coercion?
Message ID:
358541450.979674.1640630105012@mail.yahoo.com
Hi all,
This is not a pre-RFC, but I think most of us have been bitten at times by bugs like this:
my @values = (in => "data.csv");
$values[2]++;
Except that $values[2] was the string "n/a" and now it's "1".
The core of the idea is simple. it would be lovely to have something to prevent implicit coercion in a given lexical scope:
use explicit;
my $num = 3; # integer
$num += .42; # fatal because it creates a float
Instead, we have to do this:
use explicit;
my $num = 4;
$num = float($num);
# or `$num = 4.0;`
$num += .42; # works just fine
This would also be fatal:
use explicit;
my $value = {};
say ++$value;
Is this possible? I realize there are many edge cases.
Best,
Ovid
--
IT consulting, training, specializing in Perl, databases, and agile development
http://www.allaroundtheworld.fr/.
Buy my book! - http://bit.ly/beginning_perl
Thread Next
-
No implicit coercion?
by Ovid via perl5-porters