PERL Journal Clock Example: Difference between revisions
(Created page with " [http://www.foo.be/docs/tpj/issues/vol1_1/tpj0101-0005.html PERL Journal Article intro to CGI programming] Original PERL code by Lincoln Stein: <source lang="perl"> #!/usr/b...") |
m (Michael Murtaugh moved page PERL Journal to PERL Journal Clock Example) |
||
(One intermediate revision by the same user not shown) | |||
Line 25: | Line 25: | ||
#!/usr/bin/python | #!/usr/bin/python | ||
from subprocess import check_output | |||
print ("Content-type: text/html\n") | |||
time = check_output(["date"]).strip() | |||
time = check_output(["date"]).strip().decode("utf-8") | |||
print """ | print (""" | ||
<HTML><HEAD> | <HTML><HEAD> | ||
<TITLE>Virtual Clock</TITLE> | <TITLE>Virtual Clock</TITLE> | ||
Line 40: | Line 40: | ||
<STRONG>{0}</STRONG>. | <STRONG>{0}</STRONG>. | ||
</BODY></HTML> | </BODY></HTML> | ||
""".format(time) | """.format(time)) | ||
</source> | </source> |
Latest revision as of 12:51, 12 February 2014
PERL Journal Article intro to CGI programming
Original PERL code by Lincoln Stein:
#!/usr/bin/perl
print "Content-type: text/html\r\n";
print "\r\n";
chomp($time = `date`);
print<<EOF;
<HTML><HEAD>
<TITLE>Virtual Clock</TITLE>
</HEAD>
<BODY>
<H1>Virtual Clock</H1>
At the tone, the time will be
<STRONG>$time</STRONG>.
</BODY></HTML>
EOF
Translated to python (nb check_output was introduced to python in version 2.7):
#!/usr/bin/python
from subprocess import check_output
print ("Content-type: text/html\n")
time = check_output(["date"]).strip().decode("utf-8")
print ("""
<HTML><HEAD>
<TITLE>Virtual Clock</TITLE>
</HEAD>
<BODY>
<H1>Virtual Clock</H1>
At the tone, the time will be
<STRONG>{0}</STRONG>.
</BODY></HTML>
""".format(time))