Use the Perl PRINT FUNCTION
There are two ways to PRINT to your browser or terminal. Luckily, whether you are using a CGI script for the web, or you are running Perl on the command line, PRINT works the same way.
The PRINT FUNCTION Example 1:
$city2="Paris";
print "I saw \"London\", and it cost me \$40.00 to take the Chunnel to $city2.<br>chris\@ilovethecode.com";
Which prints:
I saw "London", and it cost me $40.00 to take the Chunnel to Paris.
chris@ilovethecode.com
Inside of the double quotations, COMMENT OUT $ @ and " with backslashes \
We didn't COMMENT OUT the last $ because we wanted to print $city2 as a variable (Paris).
The PRINT FUNCTION Example 2:
$city2="Paris";
print <<"H";
I saw "London", and it cost me \$40.00 to take the Chunnel to $city2.<br>
chris\@ilovethecode.com
H
Pretty much the same except... you can write quotation marks to your heart's content! You need not comment them out anymore!
That might not seem like much, but it really does keep your code neater.
NOTE: The H can be any letter or set of letters you like as long as the two match and they are followed by line returns.
Copy and Paste Perl Script:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$city2="Paris";
print "I saw \"London\", and it cost me \$40.00 to take the Chunnel to $city2.<br>chris\@ilovethecode.com";
print <<"H";
<br><br>
I saw "London", and it cost me \$40.00 to take the Chunnel to $city2.<br>
chris\@ilovethecode.com
H
exit;
Perl Print Function - See in Action (new window)
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | | |
CSS David McFarland | | |
| | | |