Zsdc wrote:

> In my post from 2003-08-26 Re: Length() is bits/bytes or neither
> (Message-ID: <[EMAIL PROTECTED]>) I wrote some code illustrating
> this issue but without any comments. Anyway, I wrote a function bytes()
> which counts bytes in UTF-8 strings:
> 
>     #!/usr/bin/perl -wl
>     use utf8;
>     sub bytes ($) {
>         use bytes;
>         length $_[0];
>     }
>     $x = chr 123456;
>     print length $x, " chars";
>     print bytes $x, " bytes";
> 

you don't need to write your own function to force byte semantics when you 
feed a utf8 string to length. the length function in Perl is capable of 
doing that. the following does the same thing:

#!/usr/bin/perl -lw
use strict;
use bytes();

print length chr 123456;
print bytes::length chr 123456;

__END__

1
4

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to