in reply to int to ascii

You need to take a look at the ord, pack, and chr functions. (Look at the first example for 'pack').

map may also fit into your solution someplace. Hint hint. :)

You don't need to typecast it. Perl is a loosely-typed language. There is no syntax to typecast things in Perl.

stephen

Replies are listed 'Best First'.
Re: Re: int to ascii
by sierrathedog04 (Hermit) on May 08, 2001 at 18:58 UTC
    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?

      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.