thealienz1 has asked for the wisdom of the Perl Monks concerning the following question:

I have a binary file... and i would like to be able to view it in a text format. Like it is done in a hex editor... so far I have...
This reads in the file and goes every 8 bits, I think, and prints out the decimal value... See this is territory that I am not knowledgable about, so I am pulling this stuff out of my ass.

open(INFILE, "test.txt"); binmode(INFILE); $filecontent = join('',<INFILE>); for($x = 0; $x<length($filecontent); $x+=8) { print pack('B8',substr($filecontent,$x,8)); } close(INFILE);

Any suggestions on why it is not working...

I am the first overweight, very tall munchkin... be very amazed.

Replies are listed 'Best First'.
Re: Binary file trouble
by Fastolfe (Vicar) on Nov 08, 2000 at 21:21 UTC
    Check out Data::HexDump, which will take a binary string and convert it into a nice readable hex dump.

    Your code is basically reading 8 BYTES at a time, and trying to pack this string further. You probably want to be using unpack against each character/byte of the string.

    print join(" ", unpack('c*', $string));
    Either way, Data::HexDump will solve the problem you're apparently trying to solve. Good luck.