Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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")

In reply to (tye)Re: ASP and Storable woes by tye
in thread ASP and Storable woes by gregorovius

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-19 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found