Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

File::Binary and Carriage-Return issue

by mickeyn (Priest)
on Mar 04, 2009 at 12:24 UTC ( #748099=perlquestion: print w/replies, xml ) Need Help??

mickeyn has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks,

I use the File::Binary module (ver. 1.7) to create a binary file, this work well except for the following issue:

Whenever I have:

I get 0x0d0a (big-endian) pushed to my output binary file.

Does anyone know how to get rid of this annoying 0x0d and make the put method to only push 0x0a to the file?

Thanks in advance,

Replies are listed 'Best First'.
Re: File::Binary and Carriage-Return issue
by mickeyn (Priest) on Mar 04, 2009 at 12:30 UTC
    Problem solved.

    What happened on Windows was:

    failed to set the file-handler to binmode (in the module's documentation it says it will try... but it doesn't promise it will succeed).

    The fix for this problem was:

    binmode $fb_dst->{_fh};
    Will open a relevant bug report...


      Despite its name, it sounds from your description as if File::Binary is missing one or more calls to binmode in the correct places.

      I am on Windows and using v1.7. I cannot replicate your problem.
      >perl -MFile::Binary -wle"File::Binary->new('>file')->put_ui8(0xa0);" >debug file -rcx CX 0001 : -d100 l1 0B04:0100 A0 . -q

      Also, I cannot see how it's possible from looking at the source. binmode is getting called.

      Could you provide us with a minimal amount of runnable code that give you the problem? Are you sure you're following the instructions?

      Will try and set binmode for the handle on if possible (i.e if the object has a binmode method) otherwise you should do it yourself.

      IO::Handle objects don't have a binmode method, so you need to call binmode on it before passing the handle to ->new/->open.

        this short version recreates the problem on my machine (unmark the binmode line to compare to the fixed output):
        use strict; use File::Binary qw{$BIG_ENDIAN}; my $data = []; for (0..100) { $data->[$_] = 0x0a; } my $fb_dst = File::Binary->new("./a"); $fb_dst->set_endian(2); # 2 is $BIG_ENDIAN... fast fix $fb_dst->open(">./a"); #binmode $fb_dst->{_fh}; # unmark this line to fix problem $fb_dst->seek(0x0); my $index = 0; do { $fb_dst->put_ui8($data->[$index++]); } while ($fb_dst->tell() < 0xff);
        Thanks for your help,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://748099]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2020-11-27 11:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found