in reply to help needed on encoding a text file
You can use pack("n") for 16-bit values and pack("N") for 32-bit values. You are evidently trying to use "\0" as a separator, but this won't work because the index numbers themselves can have zero bytes in them. If you want a variable-length encoding, use pack("w"). This would be especially good if you have your most common words with the lowest index numbers, since they will come out shorter.