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

Re: ???strict??? strings?

Thread Previous | Thread Next
Zefram via perl5-porters
January 5, 2020 12:00
Re: ???strict??? strings?
Message ID:
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.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About