For example, I want to create a file called sample.bin and put a number, like 255, so that 255 is saved in the file as little-endian, FF 00. Or 3826 to F2 0E.
I tried using binmode, as the perldoc said.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Perl pack function will return “binary” data according to a template.
In the above example, the
's'tells it to output ashort(16 bits), and the'<'forces it to little-endian mode.In addition,
':raw'in the call toopentells it to put the filehandle into binary mode on platforms where that matters (it is equivalent to usingbinmode). The PerlIO manual page has a little more information on doing I/O in different formats.