Front page | perl.perl5.porters |
Postings from January 2012
Re: pack and ASCII
Thread Previous
|
Thread Next
From:
Eric Brine
Date:
January 10, 2012 13:33
Subject:
Re: pack and ASCII
Message ID:
CALJW-qG9JKy7GhX==zVV3Fodu1XGirLLofNf_nO0qaHFsHiyOA@mail.gmail.com
---------- Forwarded message ----------
From: Eric Brine <ikegami@adaelis.com>
Date: Tue, Jan 10, 2012 at 4:29 PM
Subject: Re: pack and ASCII
To: Jesse Luehrs <doy@tozt.net>
On Tue, Jan 10, 2012 at 3:58 PM, Jesse Luehrs <doy@tozt.net> wrote:
> > bytes::length does not return the number of bytes in $foo.
>
> Then what does it return? What does that '2' represent?
>
It represents the number of bytes used by Perl to store the string.
For example, bytes::length($foo) can return 2 when $foo can contain nothing
but a byte.
> > C<< pack "A1" >> will never return more than one octet.
> >
> > If only that were the case.
> > >
> >
> > Then give an example where it doesn't.
>
> It doesn't in the example given above.
>
> $ perl -MDevel::Peek -E'use utf8; my $foo = pack "A1", "ţ"; Dump($foo)'
> SV = PV(0x2360160) at 0x2376ee8
> REFCNT = 1
> FLAGS = (PADMY,POK,pPOK,UTF8)
> PV = 0x237f7c0 "\305\243"\0 [UTF8 "\x{163}"]
> CUR = 2
> LEN = 16
>
As you can see, $foo contains 0x163, which isn't a byte. $foo doesn't
contain any bytes, much less two.
That is clearly two octets - \305 and \243, unless you're using some
> other definition of "octet".
>
\305 and \243 aren't in $foo.
>
> Or am I misunderstanding something here?
>
Yeah, you're not looking in the right place. You keep looking at how Perl
stores the string (which is irrelevant) instead of what the string contains.
- Eric
Thread Previous
|
Thread Next