Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a newline in Perl using CGI

Status
Not open for further replies.

sdslrn123

Technical User
Jan 17, 2006
78
GB
#!/usr/bin/perl

use CGI;

$query = CGI::new();

$hello1=$query ->param("hello1");
$wowser=$query ->param("wowser");

print $query ->header();
print "\n";
print $query ->p("Your text is $hello1\n");
print $query ->p("Your pattern is $wowser\n");

($newhello = $hello1) =~ s/\s+//g;
print "$hello1 minus all whitespace: $newhello\n";

($newwowser = $wowser) =~ s/\s+//g;
print "$wowser minus all whitespace: $newwowser\n";




Hi I am using this perl program in a CGI.
Why do the last two print statements print on the same line?
Any help, I am very grateful.
 
For a browser to understand new line you will have to use
<br>.
 
Sorry, I'm kinda new to this. Where would I place the <br>?
 
It's interesting that you're learning how to write a CGI without understanding HTML.

You'd use <br>'s where you would want the \n's to appear. So,

print "$hello1 minus all whitespace: $newhello<br>";

I'd highly recommend looking into some HTML tutorials. Because what your average CGI typically does is print out an HTML document for your browser to display.

(that being said, $query->p basically writes "<p>(your text)</p>" as HTML code)
 
I learned Perl before I knew most HTML stuff. Perl makes sense, HTML just doesn't.
 
Thank you very much. Muchos Gracios.
Have a great weekend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top