Solved

How to print html

Posted on 2009-05-07
3
147 Views
Last Modified: 2012-05-06
How would I print out embedded html in perl.  For example this works

print <<EOF;
<html>
<head>
<title>My HTML page</title>
</head>
<body>
<br>
First Message to print out
<br>
Second message to print out
<br>
Third message to print
</body>
</html>
EOF

however I want to add an if statement to determine which message to print out.   I tried the following with no luck

print <<EOF;
<html>
<head>
<title>My HTML page</title>
</head>
<body>
<br>
EOF

if($test == 0){
print <<EOF;
First Message to print out
<br>
EOF
}
else{
print <<HTML;
Second message to print out
<br>
HTML
}
print <<HTML;
</body>
</html>
HTML



0
Comment
Question by:warrior32
3 Comments
 
LVL 28

Accepted Solution

by:
FishMonger earned 200 total points
ID: 24328504
my $firstmsg = <<EOF;
First Message to print out
<br>
EOF

my $secondmsg = <<HTML;
Second message to print out
<br>
HTML

print $test == 0 ? $firstmsg : $secondmsg;
0
 
LVL 84

Expert Comment

by:ozo
ID: 24329327
There are other ways to do it, but what was unlucky about what you tried?
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 50 total points
ID: 24329709
For this type of stuff, it is usually easier to use one of the HTML template modules.  Eithter HTML::Template or Template Toolkit:
    http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm
    http://search.cpan.org/~abw/Template-Toolkit-2.20/lib/Template.pm
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Insert Text into odbc.ini file 15 70
batch script for automated email 12 132
Ned Perl Snippet to Read Files in Directory 5 79
Matching a random pattern with one common character 2 83
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question