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:
Leon Timmermans
Date:
January 27, 2011 03:23
Subject:
Re: Changing variable to numeric without assignment (was: Using smart matching)
Message ID:
AANLkTi=C420q_3X-SvYy-wELbtXie1fZ9JFS4fUQH7=u@mail.gmail.com
On Thu, Jan 27, 2011 at 12:17 PM, Ed Avis <eda@waniasset.com> wrote:
> I see.  Personally, I'd take 'correct, but slightly slower' over 'a bit faster
> in some cases, with surprising edge cases' any day.  But isn't it possible to
> have it both ways?  The numeric value could be cached in the scalar and used
> next time, but without flipping the switch to mark the scalar as numeric.  Then
> later numeric context uses would be fast, but the value would not mysteriously
> change.
>
> I have only a loose idea of Perl internals so please forgive my ignorance here;
> from a user's point of view not changing a variable just because it was *read*
> in an arithmetic expression is definitely the right thing to do, but I am
> uncertain of the practicalities of doing so in the perl interpreter.

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.

Leon

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