epoptai has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a webmail script and saving sent mail to a pipe delimited flat file like so:
The problem was line breaks from the textarea messing up the $body part. I tried many combinations of textarea properties and such but only $body=~s/\n/ /g; got it all on one line, but that solution ruined the formatting of the original message which needs to be preserved.print FILE "$when|$to|$from|$subject|$body\n";
My solution is to uuencode the contents of $body for saving, and uudecode $body for displaying. It seems to work very well but wonder if it's the best way or if there may be unforseen problems down the road.
Sample record:my $encoded_body = pack ("u", $body); $encoded_body=~s/\n//g; print FILE "$when|$to|$from|$subject|$encoded_body\n";
Decoding:Fri Dec 15 15:34:10 2000|to@net.net|from@net.net|Hello|E5&AI<R!I><R!T: +&4@><V%M><&QE(&UE><W-A9V4A#0H-"D)Y92X-"@`` >
Yields:$decoded_body = unpack ("u", $encoded_body);
thanks - epoptaiThis is the sample message! Bye.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: uuencoding to deal with line breaks
by dws (Chancellor) on Dec 16, 2000 at 02:58 UTC | |
by epoptai (Curate) on Dec 16, 2000 at 06:11 UTC | |
by I0 (Priest) on Dec 16, 2000 at 06:47 UTC | |
by epoptai (Curate) on Dec 16, 2000 at 09:36 UTC | |
|
Re: uuencoding to deal with line breaks
by I0 (Priest) on Dec 16, 2000 at 02:19 UTC | |
|
Re: uuencoding to deal with line breaks
by ichimunki (Priest) on Dec 16, 2000 at 05:02 UTC | |
by epoptai (Curate) on Dec 16, 2000 at 13:08 UTC | |
by eg (Friar) on Dec 16, 2000 at 15:27 UTC | |
by epoptai (Curate) on Dec 19, 2000 at 04:51 UTC |