in reply to Re: File::Binary and Carriage-Return issue
in thread File::Binary and Carriage-Return issue

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.

Replies are listed 'Best First'.
Re^3: File::Binary and Carriage-Return issue
by mickeyn (Priest) on Mar 04, 2009 at 13:23 UTC
    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,
    Mickey

      Don't post program you didn't actually run!!!!

      Update: I can't trust your observations, and I can't replicate them either.

      There's a bug in File::Binary that makes it incapable of exporting symbols. I switch to using

      # Useless since we only output bytes. $fb_dst->set_endian($File::Binary::BIG_ENDIAN);

      Then I get

      >debug file -rcx CX 00FF : -d100 lff 0B05:0100 0A 0A 0A 0A 0A 0A 0A 0A-0A 0A 0A 0A 0A 0A 0A 0A ......... +....... 0B05:0110 0A 0A 0A 0A 0A 0A 0A 0A-0A 0A 0A 0A 0A 0A 0A 0A ......... +....... 0B05:0120 0A 0A 0A 0A 0A 0A 0A 0A-0A 0A 0A 0A 0A 0A 0A 0A ......... +....... 0B05:0130 0A 0A 0A 0A 0A 0A 0A 0A-0A 0A 0A 0A 0A 0A 0A 0A ......... +....... 0B05:0140 0A 0A 0A 0A 0A 0A 0A 0A-0A 0A 0A 0A 0A 0A 0A 0A ......... +....... 0B05:0150 0A 0A 0A 0A 0A 0A 0A 0A-0A 0A 0A 0A 0A 0A 0A 0A ......... +....... 0B05:0160 0A 0A 0A 0A 0A 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:0180 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:0190 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:01A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:01B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:01C0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:01D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:01E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ......... +....... 0B05:01F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 ......... +...... -q

      as expected.

      Windows and version 1.7

        sorry about that, couldn't share the original code...

        I corrected the code above - ran it and it does recreate the problem on my Windows:

        % hexdump a 0000000 0a0d 0a0d 0a0d 0a0d 0a0d 0a0d 0a0d 0a0d * 00000c0 0a0d 0a0d 0a0d 0a0d 0a0d 0000 0000 0000 00000d0 0000 0000 0000 0000 0000 0000 0000 0000 * 00000f0 0000 0000 0000 0000 0000 0000 0000 0000 00000ff
        Mickey