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

Re: pack and ASCII

Thread Previous | Thread Next
Jesse Luehrs
January 10, 2012 23:13
Re: pack and ASCII
Message ID:
On Wed, Jan 11, 2012 at 01:36:23AM -0500, Eric Brine wrote:
> On Tue, Jan 10, 2012 at 5:54 PM, Leon Timmermans <> wrote:
> > Not true. Those aren't exclusive. Right now, both DWIM. The former returns
> >
> > exactly one byte. The latter returns exactly one character.
> >
> >  They don't DWIM for me. I mean to get a bytestring as result.
> If you have code that requires a UTF8=0 string specifically, it is buggy.
> Specifically, it suffers from the Unicode bug. You are probably using SvPV
> without looking at the SvUTF8. The solution is simple: Use SvPVbyte instead.

There has to be some point when code can assume that it has a byte
string. What Leon is saying is that it's a lot more useful for pack to
use SvPVbyte itself automatically, since pack is typically used for
things like binary protocols and file formats, which are usually defined
in terms of bytes, not characters.

> > You still didn't say what you think the two formats should do.
> >
> >  I want reliable byte semantics when I'm using pack. If other people
> > want character semantics that should be separate from this. This
> > polymorphism is madness.
> >
> I do no understand that answer at all.
> What should pack("A*", $_) return for a byte, and what should it return for
> a non-byte?

It should be an error (or at least a warning) for the 'A' format to
receive a non-byte.


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