One solution is to change the delimiter in your text file to something that will not be present in the input field.

For example you could use a double linefeed to seperate records then single line feeds would not end your record. This has the obvious problem of what if the user enters a blank line. You could trim any double linefeeds out of course and this method retains the format that the user put the data into the form as a side effect.

The problem with the current code which would be noted under use warnings; is that you are making up a new copy of address 3 times in the code.

my $address=$query->param('address'); $address =~ s/\n/<br>/g; $address =~ s/\r//g;

See if that makes it better. warnings would say some thing similar to: my declaration masks variable in same scope.


In reply to Re: How to handle new lines in textfield (CGI) by dga
in thread How to handle new lines in textfield (CGI) by jonnyfolk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.