<?xml version="1.0" encoding="windows-1252"?>
<node id="121382" title="Re: Bin\Hex Parsing in Perl ?" created="2001-10-25 05:46:25" updated="2005-07-19 14:08:11">
<type id="11">
note</type>
<author id="41288">
jeroenes</author>
<data>
<field name="doctext">
Other monks learned me how to doo this some while ago. A bit confused though whether you are trying to read/write &lt;i&gt;binary&lt;/i&gt; or a &lt;i&gt;text&lt;/i&gt; file populated with hexidecimal characters. 

&lt;p&gt;

Your method seems fine to me, but writing in general can be done just using the [print] command, whether or not your strings are binary. On win32 you do need the [binmode] command, though.

&lt;p&gt;

For reading you could also use this to fetch fixed-length records:
&lt;code&gt;my $rec;
do_something( $rec) while read(FILE, $rec,$reclength);&lt;/code&gt;
&lt;p&gt;

With un[pack] you can translate both binary and hexidecimal data:

&lt;code&gt;@hd = unpack 'h*', $rec;
@floats = unpack 'f*', $rec;&lt;/code&gt;
&lt;p&gt;

So the exact name of what you are trying to do? Reading binary files, unpacking ....

&lt;p&gt;

I will have a look into that Data:Hexdump module. It's probably worth it.

&lt;p&gt;

Mehopes it's all a bit clearer to you now.

&lt;p&gt;

Jeroen&lt;br&gt;

&lt;i&gt;"We are not alone"(FZ)&lt;/i&gt;
&lt;p&gt;
&lt;b&gt;Update: &lt;/b&gt; I've read the HexDump docs, and what it does
is just to make a binary file ready for human reading like 
in a hex viewer. So it's very usable to dump a bin file 
on a tty, but not fit to parse a binary file for
subsequent use in a script. See the code above.  </field>
<field name="root_node">
121277</field>
<field name="parent_node">
121277</field>
</data>
</node>
