in reply to Re: uuencoding to deal with line breaks
in thread uuencoding to deal with line breaks

Covered this one, but your post got me thinking about efficiency. 30k of text uuencodes to 40k and urlencodes to 47k. I wonder if there's a way to use pack or some other technique within perl to compress text, or at least improve on uu.

?

  • Comment on Re: Re: uuencoding to deal with line breaks

Replies are listed 'Best First'.
Re: Re: Re: uuencoding to deal with line breaks
by eg (Friar) on Dec 16, 2000 at 15:27 UTC

    Uuencoded output will always be larger than the input because what you're doing is mapping the 8-bit character set into a smaller one (6-bits?).

    If you want to compress your data, use Compress:Zlib (or maybe some form of `gzip -cf`) and uuencode the compressed data like before.

    If that's still too big for you (or if you like complications), you can save your data as

      $when|$to|$from|$subject|$body_length|$binary_compressed_body";
    

    and use read or sysread to read $binary_compressed_body.

    Come to think of it, if the formatting of the body is important to you, why not just save the number of lines in the body as the 5th data field rather than the body itself and have the exact body text follow it? So it would look like

    $when|$to|$from|$subject|$lines_in_body
    $body   # could be multi-lined
    
      Thank you eg! Uuencoded zlib is the answer, it's about 85% smaller than plaintext.
      use Compress::Zlib; use HTML::Entities; sub zlibc{ # zlib compress $output = compress($input); $output = pack ("u", $output); $output = encode_entities($output)} sub zlibu{ # zlib uncompress $o = decode_entities($input); $o = unpack ("u", $o); $output = uncompress($o)}
      Update: suffered some downvotes because i didn't realize how badly color-coded perl would go over.

      That won't happen again =)