Perl CGI problem

i wrote :
  if ($qs{'question'}) {
      $question = "$qs{'question'}";
      $question =~ s/\cM//g;
      $question =~ s/\n\n/<p>/g;
      $question =~ s/\n/<br>/g;

      $question =~ s/&lt;/</g;
      $question =~ s/&gt;/>/g;
      $question =~ s/&quot;/"/g;
   }

to format my output of $question in html.

what what does \cM mean?

when I fill in :
xxx yyy zzzz
aaaaaaaa

and the html shows:
xxxyyyzzzz
aaaaaaaa


what is the problem? how can i corret it?
mwhuenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

djsansuiCommented:
\c means Control, therefore \cM is the equivelant to CTRL+M.  CTRL+M gives the same result as \n, it is a newline character.  What it is doing is taking out all of the CTRL+M characters (because HTML forms usually submit a newline as both CTRL+M and \n, so you'd end up with double line breaks)

I was unable to replicate the problem which you describe, there may be some code somewhere else that is causing it, but try using the commands in this order:

$question =~ s/\n\n/<p>/g;
$question =~ s/\n/<br>/g;
$question =~ s/&lt;/</g;
$question =~ s/&gt;/>/g;
$question =~ s/&quot;/"/g;
$question =~ s/\cM//g;

If this doesn't solve your problem, then post any parts of the program that refer to $question  or $qs{'question'}.  Also, print $qs{'question'} before anything happens to it (immediately after it is created) and post what that prints as also.
     
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mwhuenAuthor Commented:
thanks for your comment, but it doesn't work.
can you explain more about these lines:

#       $qs{$k} =~ s/&/&amp\;/g;
#       $qs{$k} =~ s/</&lt\;/g;
#       $qs{$k} =~ s/>/&gt\;/g;
#       $qs{$k} =~ s/"/&quot\;/g;

why we need these conversion?
how useful of them?

and :

     # $question =~ s/&lt;/</g;
     # $question =~ s/&gt;/>/g;
     # $question =~ s/&quot;/"/g;

why convert them back?

0
mwhuenAuthor Commented:
it works now. i made a mistake when
tr/\+/ /g;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.