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

No implicit coercion?

Thread Next
Ovid via perl5-porters
December 27, 2021 18:35
No implicit coercion?
Message ID:
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");

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.

IT consulting, training, specializing in Perl, databases, and agile development 

Buy my book! -

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