Re: [MacPerl-WebCGI] Filtering the input from a transmitet form
[email protected] (Bruce Van Allen) Fri, 10 Jan 2003 10:49:21 -0800
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <[email protected]> |
On Friday, January 10, 2003, at 10:05 AM, Eelco Alosery wrote:
> I have a problem when I reseave a transmitet form and want to writh it
> to a data base.
> All the reseaved info must by written to a single line, but somtimes
> it starts writing multiple lines.
> This happens when there has giffen a enter for a new line in the
> textfield on the form.
The canonical way to process newlines from (almost) any source is:
$string =~ s/(\015?\012)|\015/NEW_LINE_REPLACEMENT/gs;
where NEW_LINE_REPLACEMENT is whatever you want.
If you use \n,
s/(\015?\012)|\015/\n/gs
Perl substitutes the newline construct native to the current OS.
Because of all the slashes, I find all this easier to read using pairs
of braces
=~ s{(\015?\012)|\015}{NEW_LINE_REPLACEMENT}gs;
Examples:
s{(\015?\012)|\015}{\015\012}gs Convert to DOS/Win newlines (CRLF)
s{(\015?\012)|\015}{\012}gs Convert to UNIX/Linux newlines (LF)
s{(\015?\012)|\015}{\015}gs Convert to Mac OS newlines (CR)
s{(\015?\012)|\015}{<br>}gs Convert to HMTL line breaks as a way
to store data on one line that will be returned to web display
1;
- Bruce
__bruce__van_allen__santa_cruz__ca__