maderman has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have .wst Text file (WordStar) files on a unix system and I was wondering what would be the best way to get the data out into text strings? (pack, unpack...) Thanks, Stacy.

Replies are listed 'Best First'.
Re: Binary data
by converter (Priest) on Mar 28, 2001 at 09:24 UTC

    You can get the WordStar document format at:

    http://www.wotsit.org/

    From the format document:

    A raw stream of the printable text in a WordStar file could therefore be discerned by masking off the 8th bit and discarding codes in the range of 00h through 1Fh. This method would, of course, omit all formatting and control information in the file. In addition to stripping control characters, symmetrical sequences must be stripped. See the description of symmetrical sequences below.

    I would try the following to remove control codes:

    $/ = undef; open FH, "< $wordstarfile" or die "craps. $!"; $doc = <FH>; # delete all ctrl chars except newline $doc =~ tr/\x00-\x09\x0b-\x1f//d; # turn off all high bits $doc =~ s/([\xa0-\xff])/chr(ord($1) ^ 0x80)/eg; print $doc;

    This would toss out all your control characters and formatting sequences, so you'd probably want to see what your results look like, then dive into the format document and start figuring out how much of the original formatting you want to preserve.