in reply to Re: int to ascii
in thread int to ascii

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?

Replies are listed 'Best First'.
Re: Re: Re: int to ascii
by chipmunk (Parson) on May 08, 2001 at 19:22 UTC
    Yes, who said that 'A' is a byte? 'A' is merely the ASCII representation of the byte 0x41. If you were using a different character set, then print pack("cccc",65,66,67,68) could very well produce different output.