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" }
Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.