in reply to ASP and Storable woes

uuencoding seems like a bit of overkill in order to drop the 8th bit. Here is a much simpler method (well, it is conceptually simpler but Perl's built-in uuencoding makes it harder to code in Perl) that might be much faster. It most likely (depending on the concentration of "8-bit characters") will write more bytes but that might not be much of a problem in comparison to the CPU usage of uuencoding. Then again, encoding perl.exe my way takes a ton fewer bytes than uuencoding does.

The concept is to pick two 7-bit characters, $quote7 and $quote8. $quote7 is used to "quote" these two characters. $quote8 is used to "quote" any "8-bit characters". So you replace any 8-bit character with $quote8 followed by that character with the 8th bit stripped. You preceed any occurrances of $quote7 or $quote8 with $quote7. I hope it is obvious how you reverse the process.

Here are the conversion routines wrapped in a test program (and it actually works):

#!/usr/bin/perl -w use strict; { my( $quote7, $quote8, %quote, %unquote ); BEGIN { $quote7= pack "C", 0x7e; # Any 7-bit char. $quote8= pack "C", 0x7f; # Any _other_ 7-bit char. @quote{ $quote7, $quote8 }= ( $quote7.$quote7, $quote7.$quote8 ); @quote{ map { pack "C", $_ } 0x80..0xff }= map { $quote8 . pack "C", $_ } 0..0x7f; %unquote= reverse %quote; } sub strip8 { my( $bin )= @_; $bin =~ s#([$quote7$quote8\x80-\xff])#$quote{$1}#go; return $bin; } sub restore8 { my( $str )= @_; $str =~ s#([$quote7$quote8].)#$unquote{$1}#gos; return $str; } } die "Usage: $0 file\n" if 1 != @ARGV; open IN, "<$ARGV[0]" or die "Can't read $ARGV[0]: $!\n"; binmode IN; undef $/; my $in= <IN>; my $out= strip8( $in ); my $end= restore8( $out ); die "Well, that didn't work!" if $in ne $end;

I used the hashes in a quest for execution speed but since I didn't run benchmarks I can't guarentee that other methods aren't tons faster.

        - tye (but my friends call me "Tye")