problems with the \n escape character 
Author Message
 problems with the \n escape character

I am using web based Perl and I am having problems with the \n escape
character.  The code is this:

print "What do you get if you multiply 6 by 9?  42\n";
print "We apologize for the inconvenience.";

I get this as output:

What do you get if you multiply 6 by 9? 42 We apologize for the
inconvenience.

What is going on?



Mon, 23 May 2005 05:07:47 GMT  
 problems with the \n escape character
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In a fit of e{*filter*}ment on 4 Dec 2002 13:07:47 -0800,

Quote:
> I am using web based Perl and I am having problems with the \n escape
> character.  The code is this:

> print "What do you get if you multiply 6 by 9?  42\n";
> print "We apologize for the inconvenience.";

> I get this as output:

> What do you get if you multiply 6 by 9? 42 We apologize for the
> inconvenience.

> What is going on?

\n isn't recognised as HTML (same as hitting enter while writing a Web
page).

Replace \n with <br />\n (<br /> being the HTML newline tag).

HTH.

Regards,

  Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPe5zjWfqtj251CDhEQIyXQCfRbgf1sIAFPZ9P0TlzhR1QhErHWIAn1o0
kflM5iSwVlcBnBwucY93dmOm
=XMaU
-----END PGP SIGNATURE-----

--
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.



Mon, 23 May 2005 05:27:15 GMT  
 problems with the \n escape character

Quote:

> I am using web based Perl and I am having problems with the \n escape
> character.  The code is this:

> print "What do you get if you multiply 6 by 9?  42\n";
> print "We apologize for the inconvenience.";

> I get this as output:

> What do you get if you multiply 6 by 9? 42 We apologize for the
> inconvenience.

I bet this is not what you are getting as output.
I bet as Perl output you are getting
    What do you get if you multiply 6 by 9?
    42 We apologize for the inconvenience
in two(!) lines.
I also take the risk of guessing that you are not telling the whole story. I
bet this is a stealth CGI question. Or actually even an HTML question.
Did you hide from us that your Perl script is generating HTML code?
Did you hide from us that this HTML code is displayed in a web browser?
Did you hide from us that what you claimed to be the output of your script
is actually the rendered text you observed in the browser?

I bet it is.
And in that case you may want to think about how to code a line break in
HTML.

jue

Oh, btw: this is a very frequently asked question about HTML. Astonishingly
enough it's never asked in an HTML newsgroup.



Mon, 23 May 2005 08:48:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Formats: Escaping Characters

2. CGI hangs due to dodgy escape character

3. Escaping cursor characters

4. Variables and escaped characters in RegExp

5. how do I retranslate escaped characters

6. regex to escape special characters

7. Striping VT100 escape characters from a file

8. Why do escape characters show when printing?

9. Which characters need escaping list?

10. Automatically escape characters?

11. How to convert literal escape to ascii character?

12. backtick operator and escape characters...

 

 
Powered by phpBB® Forum Software