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})

--
ZSDC Perl and Systems Security Consulting


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



Reply via email to