start page | rating of books | rating of authors | reviews | copyrights

Book HomeJava and XSLTSearch this book

8.30. bytes

The use bytes pragma disables character semantics for the rest of the lexical scope in which it appears. no bytes can reverse the effect of use bytes within the current lexical scope. Perl normally assumes character semantics in the presence of character data (i.e., data from a source marked as being of a particular character encoding). When use bytes is in effect, the encoding is temporarily ignored, and each string is treated as a series of bytes.

bytes is used as follows:

$x = chr(400);
    print "Length is ", length $x, "\n";     # "Length is 1"
    printf "Contents are %vd\n", $x;         # "Contents are 400"
    {
        use bytes;
        print "Length is ", length $x, "\n"; # "Length is 2"
        printf "Contents are %vd\n", $x;     # "Contents are 198.144"
    }


Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.