in reply to Textarea boxes in CGI

The three line-endings I've encountered are \n from UNIX, \r\n from DOS, and \r from some Mac's. I usually preprocess multiline strings from forms with:
s/\r\n/\n/g; s/\r/\n/g;
This puts everything in UNIX-style line endings.

You could also do this in your split:

split(/\r\n|\r|\n/,$s)
; this is probably a little faster, and saves you a chomp.

Replies are listed 'Best First'.
Re: Re: Textarea boxes in CGI
by edoc (Chaplain) on Jun 18, 2003 at 07:27 UTC

    so a general input filter that leaves us with unix line endings for all three would be

    s/\r\n?/\n/g;

    cheers,

    J

Re: Re: Textarea boxes in CGI
by eweaverp (Scribe) on Jun 18, 2003 at 17:36 UTC
    Thanks everyone!... I ended up using the 2nd suggestion above. Although I was slightly overwhelmed by the number of varying responses :). Keep in mind that I am primarily a python person... but I understand TIMTOWTDI (in perl).

    ~evan