in reply to Re^2: how to read in a binary file and convert it to ascii output
in thread how to read in a binary file and convert it to ascii output
That makes it sound like you want to read through a file that contains both "printable" and "non-printable" byte values, and display only the printable (ascii) stuff. On unix, there is a command called "strings" to do exactly that.
A perl implementation would be something like this (assuming the file is not too big to hold in memory):
You could tweak that to print only strings that are some minimum length, etc. Anything else you know about the binary file (e.g. strings of interest are all terminated by null bytes, or something like that) could be used to good effect in making sure you only print the interesting parts.$_ = do { local $/; <> }; s/[^\t\n\r -~]+/\n/g; print;
|
|---|