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

Hi, i'm Fred from the Netherlands. i'm trying to change some html code in a cgi script. But i don't remember witch Characters must block with a backslash "\" to get no problems. I know that is needed by " and @ but what are the others??? please, can sombody tell me!? greate thanks in advance.. Fred ( fdebpc1@gmail.com )

Replies are listed 'Best First'.
Re: bad (html) characters in perl/cgi
by ikegami (Patriarch) on Jul 27, 2006 at 22:43 UTC

    It depends on the type of literal.

    • In double-quoted strings literals, \, $, @ and " must be escaped. Many other characters may be escaped (but definitely not letters).
    • In qq string literals: \, $, @ and the string delimiter must be escaped. Many other characters may be escaped (but definitely not letters)
    • In <<... string literals: \, $, @ must be escaped. Many other characters may be escaped (but definitely not letters)
    • In <<"..." string literals: \, $, @ must be escaped. Many other characters may be escaped (but definitely not letters)

    • In single-quoted string literals: \ and ' (and no other character) must be escaped.*
    • In q string literals: \ and the string delimiter (and no other character) must be escaped.*
    • In <<'...' string literals: \ (and no other character) must be escaped.*

    *\ does not need to be escaped in single-quoted and similar string literals if it's followed by a character that doesn't need to be escaped.

      hey, thanks for your asnwer! grtz, Fred