develooper Front page | perl.perl5.porters | Postings from January 2011

Re: Changing variable to numeric without assignment (was: Using smart matching)

Thread Previous | Thread Next
From:
Ed Avis
Date:
January 27, 2011 06:39
Subject:
Re: Changing variable to numeric without assignment (was: Using smart matching)
Message ID:
loom.20110127T153518-202@post.gmane.org
Leon Timmermans <fawaka <at> gmail.com> writes:

>[cases where evaluating ($b + 0) changes the value of a later expression]

>I think the real bug here is not that a scalar value can have both a
>numeric and a string value, but that some operators and keywords are
>polymorphic on the representation of the value.

Well, perhaps.  But practically, I do not suggest changing either of
those things.  It is not a problem that a scalar can have both a
numeric and a string value.  What is wrong is that the scalar can
somehow be altered just by using it in an expression, without
assigning to it or using any other explicit mutation operator.  Its
values, whatever they may be, should stay the same when you just read
it.

From a practical point of view, changing all the operators which
depend on the representation of a value might be a big task, but
changing ($b + 0) so that it just looks at the value of $b, but
doesn't alter it, seems like a smaller fix.

--
Ed Avis <eda@waniasset.com>



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