in reply to Portable string length in bytes
The pack, when used this way, will wrap the original bytes in a string that, in 5.6 and above, is marked as a byte string — not UTF-8. So length will do the right thing. In earlier versions, all strings are byte strings, anyway.my $bytecount = length pack 'C0a*', $string;
In a similar manner, one can use 'U0' on 5.6 and above, to mark the resulting string as UTF-8 — again, without altering the bytes. So it's very similar to the UTF-8-twiddling routines _utf8_on and _utf8_off in Encode with 5.8 and above, except that this here is a function. For more info, see the entry on pack in a recent version of perlfunc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Portable string length in bytes
by Anonymous Monk on Mar 31, 2003 at 21:14 UTC | |
by bart (Canon) on Mar 31, 2003 at 21:17 UTC |