I want to be able to output 0x41, and have it show up as A.
This is what I have tried so far:
my $out;
open $out, ">file.txt" or die $!;
binmode $out;
print $out 0x41;
close $out;
It outputs 65 instead of A in the resulting file. This is not what I want.
I also have read this similar question, but I wouldn't transfer the answer over. pack a short results to 2 bytes instead of 1 byte.
You can use chr(0x41).
For larger structures, you can use pack:
pack('c3', 0x41, 0x42, 0x43) # gives "ABC"
Regarding your suspicion of pack, do go read its page - it is extremely versatile. 'c' packs a single byte, 's' (as seen in that question) will pack a two-byte word.
Use the chr function:
print $out chr 0x41
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With