Zcity has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have a cgi that prints a html form and would like to remove spaces, commas, semicolons in the textarea field. What do you recommend?

2006-07-05 Retitled by planetscape, as per Monastery guidelines

( keep:0 edit:5 reap:0 )

Original title: 'cgi form'

  • Comment on Tidying up punctuation in a CGI text area

Replies are listed 'Best First'.
Re: Tidying up punctuation in a CGI text area
by davorg (Chancellor) on Jul 05, 2006 at 12:43 UTC

    Probably I'd recommend some kind of regular expression substitution on the contents of the text area.

    I can be less vague if you can.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Tidying up punctuation in a CGI text area
by Ieronim (Friar) on Jul 05, 2006 at 14:19 UTC
    Use the tr/// operator, e.g.
    $textarea =~ tr/ ,;//d;
      the tr/// works when i'm doing the print html but when im posting the text in the log file, it doesnt delete the line spaces. Any other solutions?

        That tr doesn't include new lines at all. The only reason you see it working in the HTML is because HTML always ignores newlines.


        ___________
        Eric Hodges
Re: Tidying up punctuation in a CGI text area
by derby (Abbot) on Jul 05, 2006 at 12:51 UTC

    If a regex doesn't work for you, I'd recommend not focusing too much on the output. I find that by not focusing, my vision becomes a bit blurry and then I tend not notice stuff like extra spaces or punctuation (thank you Evelyn Wood!).

    -derby