in reply to Re: Portable length() in bytes.
in thread Portable length() in bytes.

Regardless of the underlying encoding, the computer still deals with these things as bytes. Storage doesn't care whether the stuff you're storing is UTF-8 or ASCII. Nor does transmission over the network. Bytes are still a useful measure of quantity in some domains.

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Replies are listed 'Best First'.
Re^3: Portable length() in bytes.
by ysth (Canon) on Nov 07, 2004 at 22:00 UTC
    But if you have to know how much you are storing or transmitting, you need to know what your output file handle is going to do with the data. If the output file handle will be upgrading to utf8, and your data is "\xff123" (4 bytes, 4 characters, in 8-bit encoding), 5 bytes will be written. If the output filehandle downgrades utf8 and you have "\x{ff}123" (4 bytes, 5 characters, in utf8 encoding), you will be writing just 4 bytes. But how long it is in the encoding perl happens to have it stored as is not relevant.