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

Re: Bin\Hex Parsing in Perl ?

by jeroenes (Priest)
on Oct 25, 2001 at 09:46 UTC ( #121382=note: print w/replies, xml ) Need Help??

in reply to Bin\Hex Parsing in Perl ?

Other monks learned me how to doo this some while ago. A bit confused though whether you are trying to read/write binary or a text file populated with hexidecimal characters.

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.

For reading you could also use this to fetch fixed-length records:

my $rec; do_something( $rec) while read(FILE, $rec,$reclength);

With unpack you can translate both binary and hexidecimal data:

@hd = unpack 'h*', $rec; @floats = unpack 'f*', $rec;

So the exact name of what you are trying to do? Reading binary files, unpacking ....

I will have a look into that Data:Hexdump module. It's probably worth it.

Mehopes it's all a bit clearer to you now.

"We are not alone"(FZ)

Update: 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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-01-21 06:34 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.