By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,848 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

Pack yields unwanted bytes

P: 1
Hello!

Maybe this question has already popped up somewhere, but I'm new to this
forum and there is apparently no way to search the past questions and
answers...
I have written a script that needs to produce binary files. I am using active perl
on windows.
I am using the function "pack" to get the bytes into the binary file.

So for instance pack("c", 0x41); results in getting the character "A" into
the file. However, if I do: pack("c", 10); , I think I should get 0x0A in my file
but instead it puts 2 bytes in the file, 0x0D, 0x0A.

Could anybody tell me how to enter exactly what I want and no extra bytes?

Here is a sample code:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. open(outfile, ">Test.bin");
  3. print outfile pack("C", 10);
  4. close(outfile);
  5.  
This works very well in MacOS-X, this does not work with ActivePerl, the
file produced has 2 bytes instead of one.

Thanks for any hint,

Pascal
Mar 10 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.