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:
Dan Book
Date:
March 11, 2022 21:25
Subject:
Re: Pre-RFC: builtin:: functions for detecting numbers vs strings
Message ID:
CABMkAVXGncT-Kiy+tix_5PfFxoZVLXjJna=n-JeQr2kjpFrQyg@mail.gmail.com
On Fri, Mar 11, 2022 at 4:19 PM William Lindley <wlindley@wlindley.com>
wrote:

> In all this discussion, what happens when reading a file containing the
> line:
>
> 01730
>
> which is the postal code for my hometown.  This "looks like" a number
> but if treated like one, the leading zero is liable be dropped, leaving
> invalid postcode
>
> 1730
>
> In more-pathological cases, 01730 could be interpreted as an octal
> number (984 decimal).
>
> It is disheartening that Perl's "be forgiving in what you accept; be
> strict at what you output" is violated by so many newer protocols.
>
>
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.

-Dan

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