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

Re: pack and ASCII

Thread Previous | Thread Next
From:
demerphq
Date:
January 12, 2012 04:40
Subject:
Re: pack and ASCII
Message ID:
CANgJU+W5ejfZ+NCgeosRjrARY68CQEVXw+dQt7K3Zf=Ouo_T2Q@mail.gmail.com
On 12 January 2012 02:45, Eric Brine <ikegami@adaelis.com> wrote:
> No, not at all. I don't care at all how Perl chooses to store a string in an
> SV. **If one has code that depends on how Perl stores a string in an SV, it
> suffers from The Unicode Bug.**

I really think you are overstating things, which is muddling this discussion.

Consider:

$ perl -MDevel::Peek -MEncode -le'Dump encode_utf8(chr(1000))'
SV = PV(0x8dae758) at 0x8db0818
  REFCNT = 1
  FLAGS = (TEMP,POK,pPOK)
  PV = 0x8dc21b8 "\317\250"\0
  CUR = 2
  LEN = 4

Why is *that* string not marked UTF8 on? Because if it were it would
be *useless*.

There are lots of cases where it is absolutely reasonable to care
about how Perl is storing a string. At the very least because Perl at
times cares how Perl is storing a string.

$ perl -MEncode -le'my $unicode= chr(1000); my $bytes=
Encode::encode_utf8($unicode); if (shift) { print $unicode } else {
print $bytes; }'
Ϩ
$ perl -MEncode -le'my $unicode= chr(1000); my $bytes=
Encode::encode_utf8($unicode); if (shift) { print $unicode } else {
print $bytes; }' 1
Wide character in print at -e line 1.
Ϩ

I will agree that *within Perl* one should almost never care what
format a string is. However when Perl is *inter-operating* with other
code or systems one MUST care what format the string is. And pack is
used to inter-operate with other code and systems, thus one is
*absolutely, without ANY debate* allowed, and indeed *encouraged* to
know what format a string is in.

So please drop this "If one has code that depends on how Perl stores a
string in an SV" argument. It is simply wrong, and it is not helpful
to keep repeating it over and over.

Cheers,
yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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