Reading C binary data from disk 
Author Message
 Reading C binary data from disk

[Posted and a courtesy copy sent.]



Quote:
> Is it possible to write out a C double (or int) using fwrite() and then open
> that file and read the double value into a Perl scalar type - using just Perl
> code??

Certainly.

perldoc -f unpack  (for the decoding function itself)
perldoc -f pack    (for the format definitions)

Don't forget to 'binmode()' the file after opening it and before reading
it.  Just in case...

--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.*-*-*.com/



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk

Quote:

> Is it possible to write out a C double (or int) using fwrite() and then open
> that file and read the double value into a Perl scalar type - using just Perl
> code??

 perldoc -f unpack
 perldoc -f pack

--

http://pobox.com/~jdf



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk

  LR> I wonder if there isn't a design flaw in the read() or sysread()
  LR> functions implemented for the Evil Empire.  Analogous to C's fread,
  LR> shouldn't they automatically give back all the bytes as they exist on
  LR> the external medium, instead of converting "\015\012" pairs to "\n"?  An
  LR> implicit binmode(), in effect, to help eliminate these recurrent bugs.  
  LR> The line-at-a-time input operators <> and readline() wouldn't be
  LR> affected by this change.

i am no expert on the evil os (thank god!), but i believe perl's binmode
calls a winblows system call to affect its conversion of cr/lf to
\n. this is needed for c programs too as c uses the \n convention. so
having perl's read and sysread do an implicit bin mode makes little
sense. they don't know what the programmer is doing (and if the
programmer is using winblows, he doesn't know what he is doing either
:-), so they can't always turn on binmode.

just trying to help out those poor POB's,

uri

--
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering

Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk
 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc,

:I wonder if there isn't a design flaw in the read() or sysread()
:functions implemented for the Evil Empire.  Analogous to C's fread,
:shouldn't they automatically give back all the bytes as they exist on
:the external medium, instead of converting "\015\012" pairs to "\n"?  

Yes, it's a bug, but it's a bug from the Evil One in their C code, and
one apparently we're not allowed to fix it.  It's nestled deep down
in the bowels of their hideous run-time system.

I, too, long believed as you believed, so when the light of truth
finally shone upon their profound iniquity, a non-trivail clean-up
job was required to rescue the random documentation (like peropentut),
as well as the ensuing mess on my hardwood floors.

    That is not dead which can ?ternal lie,
        and in strange ?ons, even CP/M may die.
            --Abdulw Al-Lhazard

--tom
--
When the dinosaurs are mating, climb a tree.  --Steve Johnson



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk

  LR> I wonder if there isn't a design flaw in the read() or sysread()
  LR> functions implemented for the Evil Empire.  Analogous to C's fread,
  LR> shouldn't they automatically give back all the bytes as they exist on
  LR> the external medium, instead of converting "\015\012" pairs to "\n"?  An
  LR> implicit binmode(), in effect, to help eliminate these recurrent bugs.  
  LR> The line-at-a-time input operators <> and readline() wouldn't be
  LR> affected by this change.

i am no expert on the evil os (thank god!), but i believe perl's binmode
calls a winblows system call to affect its conversion of cr/lf to
\n. this is needed for c programs too as c uses the \n convention. so
having perl's read and sysread do an implicit bin mode makes little
sense. they don't know what the programmer is doing (and if the
programmer is using winblows, he doesn't know what he is doing either
:-), so they can't always turn on binmode.

just trying to help out those poor POB's,

uri

--
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering

Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk
 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc,

:I wonder if there isn't a design flaw in the read() or sysread()
:functions implemented for the Evil Empire.  Analogous to C's fread,
:shouldn't they automatically give back all the bytes as they exist on
:the external medium, instead of converting "\015\012" pairs to "\n"?  

Yes, it's a bug, but it's a bug from the Evil One in their C code, and
one apparently we're not allowed to fix it.  It's nestled deep down
in the bowels of their hideous run-time system.

I, too, long believed as you believed, so when the light of truth
finally shone upon their profound iniquity, a non-trivail clean-up
job was required to rescue the random documentation (like peropentut),
as well as the ensuing mess on my hardwood floors.

    That is not dead which can ?ternal lie,
        and in strange ?ons, even CP/M may die.
            --Abdulw Al-Lhazard

--tom
--
When the dinosaurs are mating, climb a tree.  --Steve Johnson



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk

  LR> I wonder if there isn't a design flaw in the read() or sysread()
  LR> functions implemented for the Evil Empire.  Analogous to C's fread,
  LR> shouldn't they automatically give back all the bytes as they exist on
  LR> the external medium, instead of converting "\015\012" pairs to "\n"?  An
  LR> implicit binmode(), in effect, to help eliminate these recurrent bugs.  
  LR> The line-at-a-time input operators <> and readline() wouldn't be
  LR> affected by this change.

i am no expert on the evil os (thank god!), but i believe perl's binmode
calls a winblows system call to affect its conversion of cr/lf to
\n. this is needed for c programs too as c uses the \n convention. so
having perl's read and sysread do an implicit bin mode makes little
sense. they don't know what the programmer is doing (and if the
programmer is using winblows, he doesn't know what he is doing either
:-), so they can't always turn on binmode.

just trying to help out those poor POB's,

uri

--
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering

Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com



Mon, 08 Oct 2001 03:00:00 GMT  
 Reading C binary data from disk
 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc,

:I wonder if there isn't a design flaw in the read() or sysread()
:functions implemented for the Evil Empire.  Analogous to C's fread,
:shouldn't they automatically give back all the bytes as they exist on
:the external medium, instead of converting "\015\012" pairs to "\n"?  

Yes, it's a bug, but it's a bug from the Evil One in their C code, and
one apparently we're not allowed to fix it.  It's nestled deep down
in the bowels of their hideous run-time system.

I, too, long believed as you believed, so when the light of truth
finally shone upon their profound iniquity, a non-trivail clean-up
job was required to rescue the random documentation (like peropentut),
as well as the ensuing mess on my hardwood floors.

    That is not dead which can ?ternal lie,
        and in strange ?ons, even CP/M may die.
            --Abdulw Al-Lhazard

--tom
--
When the dinosaurs are mating, climb a tree.  --Steve Johnson



Mon, 08 Oct 2001 03:00:00 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. PERL or C library for reading COBOL binary data files

2. howto read binary data from files

3. Help for reading binary data

4. Reading binary data (method and style)?

5. reading binary data files

6. read binary data

7. Reading binary data from HTTP body

8. Reading binary data?

9. reading/writing binary data

10. Reading binary data...

11. Reading binary data form a PICT file

12. Reading/Parsing binary data from socket

 

 
Powered by phpBB® Forum Software