Zsdc wrote:

> david wrote:
> 
>> Zsdc wrote:
>> 
>>>    #!/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;
> 
> You're right, in every case the real counting is done by the
> CORE::length, which only needs a little hint in $^H. The bytes::length
> subroutine is actually just:
> 
>    { BEGIN { $^H |= 8 } CORE::length $_[0] }
> 
> so you don't even need to use the bytes pragma at all. TMTOWTDI I guess.
> (Of course messing with $^H is not exactly what I call elegant, but
> still it's funny to write things like: use strict; BEGIN{$^H^=1538})
> 

i think you cite perldoc perlvar incorrectly to assume 1538 is the correct 
bits for the bytes pragma:

$^H     WARNING: This variable is strictly for internal use only.  Its
               availability, behavior, and contents are subject to change
               without notice.

this might break your code in future version of Perl.

david

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

Reply via email to