Hello everyone,

I've been having a problem parsing through a .bin file. Ideally, I want the script to read the .bin file, find the first word in it, write down word 1 somewhere else, and continue on throughout the file, word by word. I've tried similar things such as

open (MYFILE, 'data.txt');
while (<MYFILE>) {
chomp;
print "$_\n";
}
close (MYFILE);

but it is not effective for the .bin. Any help would be greatly appreciated.

Hello everyone,

I've been having a problem parsing through a .bin file. Ideally, I want the script to read the .bin file, find the first word in it, write down word 1 somewhere else, and continue on throughout the file, word by word. I've tried similar things such as

open (MYFILE, 'data.txt');
while (<MYFILE>) {
chomp;
print "$_\n";
}
close (MYFILE);

but it is not effective for the .bin. Any help would be greatly appreciated.

Would you please post example data?

It's hard to know how to handle the data if we don't know how it's read in by the script.

considering that a .bin file is a compressed and encoded file its no wonder you can't just open it like a text file.

There is no standard way that I am aware of. It really makes no sense to search a bin file for "words" but maybe for school work it does.

If you are using unix/linux or cygwin on winders, use the strings() command, as in

strings filename.bin

This command extracts every sequence of printable characters followed by an unprintable character.

Exercises for the student include working with multi-byte character strings, calling the strings command from within perl, and searching for equivalent functionality in perl.

This article has been dead for over six months. Start a new discussion instead.