Akio Yanagawa Akio Yanagawa - 2 months ago 17
Perl Question

New Line Character in Perl script

Sorry for this novice question, but new line character in Perl script doesn't work. That is, \n and \t in the script below doesn't work at all, and it just displays "Hello Perl! Hello CGI!" in one line. Usually, what is the cause of this phenomenon? Please let me know if anyone knows about it. Thank you very much.

#!/usr/bin/perl

print "Content-Type: text/html; charset=UTF-8\n\n";

print "Hello Perl!\n";
print "Hello \t CGI!";

Answer

\n and \t doesn't show in html as you expect. You can however use plain text to check that these chars are in your output,

#!/usr/bin/perl

print "Content-Type: text/plain; charset=UTF-8\n\n";

print "Hello Perl!\n";
print "Hello \t CGI!";