develooper Front page | perl.perl5.porters | Postings from March 2022

Re: Pre-RFC: builtin:: functions for detecting numbers vs strings

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
March 15, 2022 05:55
Subject:
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
CAExogxOM53AZx8Bs1_s-P++=9pN_tqStgBab5NH8=4-NVVRVKg@mail.gmail.com
>
>
> 2022-3-14 21:51 Arne Johannessen <aj22@thaw.de> wrote:
>
>> Yuki Kimoto wrote:
>> >
>> > My understanding:
>> >
>> > Perl 5.36+ can detect a string and a number completely.
>> >
>> >   a string - SvPOK
>> >   a number - (SvIOK or SvNOK) and not SvPOK
>>
>> No, I think Perl has always been able to do this. Deep down, it is
>> currently implemented like this:
>>
>>     is a string - SVp_POK
>>     is a number - SVp_IOK or SVp_NOK
>>
>> Note that scalars can be, and indeed often are, strings and numbers at
>> the same time. The new feature in 5.36 is that Perl can now also detect if
>> a value /started/ as a string or number, which is important to know in some
>> rare use cases:
>>
>>     created as string - SVf_POK
>>     created as number - (SVf_IOK or SVf_NOK) and not SVf_POK
>>
>>
>
>
I can't understand the word "started"(and "created") not yet.

This is because I don't know the cases that the value is changed after
"started".

A value is started as a number (3). If the value is used as a string, "3"
is maybe cached to the pv slot.

A value is started as a string ("3"). If the value is used as a number, 3
is maybe cached to the nv or iv slot.

As Darren says, Is the value classified to a string or a number from the
starting to the destruction, not only starting?

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