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

Re: ???strict??? strings?

Thread Previous | Thread Next
From:
Zefram via perl5-porters
Date:
January 5, 2020 12:00
Subject:
Re: ???strict??? strings?
Message ID:
20200105120030.nlfpyxy6xsdwhtxd@fysh.org
Felipe Gasper wrote:
>Has it ever been considered to make such cases trigger exceptions
>rather than coercions? i.e., a JSON encoder would reject byte strings,
>and Perl would reject character strings when printing to filehandles
>that lack an encoding.

Yes, it has been considered, and discussed here a handful of times.
It is impossible to achieve, because Perl doesn't distinguish between
character strings and byte strings.  "\xc2\xa9" serves as both a character
string and a byte string; which it is in any particular situation depends
on what the program intends to do with it.  perl cannot discern the
program's intent except by the operations actually performed on it, and
note that no computational operation is required to change the intent.
(Latin-1 encoding or decoding is an intensionally significant operation,
but an identity operation at the Perl level.)

There is thus no opportunity for perl to perceive a mismatch between the
intended use of a string and the operations actually performed, except in
the obvious case of a string with a non-octet codepoint (which therefore
can't be an octet string) being subjected to an octet string operation.
But even introducing errors for those of the obvious cases that don't
already error is a controversial proposition.

-zefram

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