in reply to print packed string

A packed string is basically a base 256 integer. For example, the string 'AB' would represent the integer 65 + 66 * 256 (65 and 66 being the ASCII codes of A and B respectively).

The H format asks pack to treat the next argument as an hexadecimal string. Since 15 is an integer, it is first converted to the string '15', which is then parsed as an hex-string, giving the number 21 (1 * 16 + 5). This number is then encoded in base 256, giving the character with ASCII code 21.

pack('H*', 15) eq chr 21

Since chr 21 isn't a printable character (it's actually Negative Acknowledge), it is rendered with this weird symbol you saw. This is largely system-dependant.

Replies are listed 'Best First'.
Re^2: print packed string
by lightoverhead (Pilgrim) on Jun 01, 2013 at 15:07 UTC

    Thank you Grimy.This is exactly what I want to know!