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

Re: No implicit coercion?

Thread Previous | Thread Next
From:
David Nicol
Date:
December 27, 2021 19:28
Subject:
Re: No implicit coercion?
Message ID:
CAFwScO-Zp9zK5OPpSVn59-pVGkCeqVRvV7xF4jXK_WtTLtAZhw@mail.gmail.com
On Mon, Dec 27, 2021 at 12:35 PM Ovid via perl5-porters <
perl5-porters@perl.org> wrote:

>
>     my @values = (in => "data.csv");
>     $values[2]++;
>
> Except that $values[2] was the string "n/a" and now it's "1".
>

Huh? $values[2] was undefined.



> 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
>

What am I missing?
sub increment_integers_or_die {
   defined(wantarray()) and croak("increment_integers_or_die called in
non-void context");
   for my $numb (@_){
          /\D/ and die "NOT AN INTEGER: >>>$numb<<<\n";
         $numb++;
   }
}

-- 
"Lay off that whiskey, and let that cocaine be!" -- Johnny Cash

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About