PERL Journal Clock Example

From XPUB & Lens-Based wiki
Revision as of 14:23, 11 February 2014 by Michael Murtaugh (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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                                                               

print "Content-type: text/html"
print

from subprocess import check_output
time = check_output(["date"]).strip()

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)