in reply to uuencoding to deal with line breaks

Based on your sample message it would appear that uuencoding the body is just going to make your flat file larger than it really wants to be. You might want to consider simply converting \n to some other control character (preferably one that won't be appearing on its own in an email) so that it doesn't interfere with using \n as a delimiter in the file.

$body =~ s/\n/\r/sg;

and then

$body =~ s/\r/\n/sg;

you might try \a, since forgetting to change this back to \n will ring the bell, which should keep people from using cat to look at the files more than once... *grin*

Replies are listed 'Best First'.
Re: Re: uuencoding to deal with line breaks
by epoptai (Curate) on Dec 16, 2000 at 13:08 UTC
    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.

    ?

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