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:
Martijn Lievaart
Date:
March 11, 2022 21:57
Subject:
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
32f71a8d-6897-2648-39bf-8cc235295dc7@rtij.nl
Op 11-03-2022 om 22:25 schreef Dan Book:
>
> Depends on how it is used in Perl syntax. If you write that as the 
> literal value: `my $x = 01730;` then you have not assigned the 
> zipcode, but an octal number. If you write it as a string: `my $x = 
> '01730';` then it will be a string containing your intended zip code. 
> Thus you must represent zipcodes as strings. Regardless, this is not 
> very relevant to the proposed functions; if anything, they allow a 
> serializer to avoid misrepresenting such a value, as long as you 
> created it properly.
>
>

Not 'if anything', it's the whole point! Perl never had a problem, you 
create a string, treat it as a string, and it will be a string. However, 
a serialiser could make a mess, as it could not distinguish a number 
from a string, so it could conceivably interpret '01730' as a number. 
With the proposed changes the serialiser can see that it "is" a string, 
so it round trips back to a string, and not a number.


M4


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