in reply to dump text file in ASCII and hex

Should it not be:

$hex = sprintf("%2x", $char);

with 2 instead of 1?

Update: Yes, of course, %02x

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."