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.

Member Avatar for onaclov2000

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.

Member Avatar for onaclov2000

That was my suspicion not sure how those are read in....

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.