Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. package bytes;
  2. $bytes::hint_bits = 0x00000008;
  3. sub import {
  4. $^H |= $bytes::hint_bits;
  5. }
  6. sub unimport {
  7. $^H &= ~$bytes::hint_bits;
  8. }
  9. sub AUTOLOAD {
  10. require "bytes_heavy.pl";
  11. goto &$AUTOLOAD;
  12. }
  13. sub length ($);
  14. 1;
  15. __END__
  16. =head1 NAME
  17. bytes - Perl pragma to force byte semantics rather than character semantics
  18. =head1 SYNOPSIS
  19. use bytes;
  20. no bytes;
  21. =head1 DESCRIPTION
  22. WARNING: The implementation of Unicode support in Perl is incomplete.
  23. See L<perlunicode> for the exact details.
  24. The C<use bytes> pragma disables character semantics for the rest of the
  25. lexical scope in which it appears. C<no bytes> can be used to reverse
  26. the effect of C<use bytes> within the current lexical scope.
  27. Perl normally assumes character semantics in the presence of character
  28. data (i.e. data that has come from a source that has been marked as
  29. being of a particular character encoding). When C<use bytes> is in
  30. effect, the encoding is temporarily ignored, and each string is treated
  31. as a series of bytes.
  32. As an example, when Perl sees C<$x = chr(400)>, it encodes the character
  33. in UTF8 and stores it in $x. Then it is marked as character data, so,
  34. for instance, C<length $x> returns C<1>. However, in the scope of the
  35. C<bytes> pragma, $x is treated as a series of bytes - the bytes that make
  36. up the UTF8 encoding - and C<length $x> returns C<2>:
  37. $x = chr(400);
  38. print "Length is ", length $x, "\n"; # "Length is 1"
  39. printf "Contents are %vd\n", $x; # "Contents are 400"
  40. {
  41. use bytes;
  42. print "Length is ", length $x, "\n"; # "Length is 2"
  43. printf "Contents are %vd\n", $x; # "Contents are 198.144"
  44. }
  45. For more on the implications and differences between character
  46. semantics and byte semantics, see L<perlunicode>.
  47. =head1 SEE ALSO
  48. L<perlunicode>, L<utf8>
  49. =cut