2008/05/16

The Labs.Com Issue_01_CGI
Last update 1999/02/20

TPJ: Issue_01_CGI

This is a collection of programs published by The Perl Journal. You can download all source-code also from TPJ: Programs.
  1. ex2
  2. ex1
  3. More Samples on CGI
Issue_01_CGI
1. ex2
Download ex2

 #!/usr/bin/perl 
  
 use CGI; 
  
 $q = new CGI; 
 if ($q->param) { 
     if ($q->param('time')) { 
         $format = ($q->param('type') eq '12-hour') ? '%r ' : '%T '; 
     } 
     $format .= '%A ' if $q->param('day'); 
     $format .= '%B ' if $q->param('month'); 
     $format .= '%d ' if $q->param('day-of-month'); 
     $format .= '%Y ' if $q->param('year'); 
 } else { $format = '%r %A %B %d %Y' } 
  
 chomp($time = `date '+$format'`); 
   
 # print the HTTP header and the HTML document 
 print $q->header; 
 print $q->start_html('Virtual Clock'); 
  
 print "<H1>Virtual Clock</H1>At the tone, the time will be\ 
  <STRONG>$time</STRONG>."; 
 print "<HR><H2>Set Clock Format</H2>"; 
  
 # create the clock settings form 
 print $q->start_form, "Show: "; 
 print $q->checkbox(-name=>'time', -checked=>1), $q->checkb\ 
 ox(-name=>'day',-checked=>1); 
 print $q->checkbox(-name=>'month',-checked=>1), $q->checkb\ 
 ox(-name=>'day-of-month',-checked=>1); 
 print $q->checkbox(-name=>'year', -checked=>1), "<P>"; 
 print "Time style: ", $q->radio_group(-name=>'type',-values=>\ 
 ['12-hour','24-hour']),"<P>"; 
  
 print $q->reset(-name => 'Reset'), $q->submit(-name => 'Se\ 
 t');  
 print $q->end_form; 
 print $q->end_html; 

Issue_01_CGI
2. ex1

Download ex1

 #!/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 

Issue_01_CGI
3. More Samples on CGI

                                                                                                                                   

Last update 1999/02/20

All Rights Reserved - (C) 1997 - 2008 by The Labs.Com

Top of Page

The Labs.Com