Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: File::Binary and Carriage-Return issue

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


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

Problem solved.

What happened on Windows was:

$fb_dst->open($file);
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...

Enjoy,
Mickey


Comment on Re: File::Binary and Carriage-Return issue
Select or Download Code
Re^2: File::Binary and Carriage-Return issue
by Corion (Pope) on Mar 04, 2009 at 12:36 UTC

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

        Which seems to mean that either IO::File is outdated or a plain call to binmode $fh would suit the same purpose yet not need the fancy OOness.

        Thanks,
        I did see this line, but it obviously didn't do what it should have, considering my above solution did the trick.

        Mickey

Re^2: File::Binary and Carriage-Return issue
by ikegami (Pope) on Mar 04, 2009 at 13:07 UTC
    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,
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://748103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2014-09-23 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (221 votes), past polls