The following program does indeed print out 'ABCD':
use strict;
my $foo = pack("cccc",65,66,67,68);
print $foo;
What I do not understand is why it works. Page 757 of Camel3 says that pack "takes a LIST of ordinary Perl values and converts them into a string of bytes."
Now who says that "A" is a byte? Maybe my operating system uses Unicode and "A" is two bytes. Isn't ASCII a 7-bit encoding scheme? (A byte is eight bits, not 7.)
So why do the bytes that pack returns necessarily print out as 'ABCD' and not as gibberish?
|