Paul Harwood wrote: > > I am trying to read a binary file with the following code: > > $filename = "binary_file.rpy"; > open(FILE, $filename) or die "can't open $filename: $!"; > > binmode(FILE); > binmode(STDOUT); > > while (read(FILE, $buff, 8 * 2**10)) { > print STDOUT $buff; > } > > I get *some* readable output, but there are still many characters that > appear as gibberish. Are there any other techniques I can use to make > the output more readable?
Here is one way to do it that converts non-printable characters to an octal escape: my $filename = 'binary_file.rpy'; open FILE, $filename or die "can't open $filename: $!"; binmode FILE; $/ = \( 8 * 2 ** 10 ); while ( <FILE> ) { s/([[:^print:]])/ sprintf '\%03o', ord $1 /eg; print; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>