Checkbox Group Illustration: Digital Clock
#!/usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

($min, $hour, $mday, $month, $year, $day) = (localtime(time))[1..6];

$month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$month];
$day   = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$day];

$year += 1900;

if (param('Set'))
{
 #  Param returns a LIST (!) of the parameters i.e., the ones
 #  specified in the -value part of the checkbox_group call.
      @timeparts = param('time_parts');
      $time = sprintf "%02d", $hour if grep {/hour/} @timeparts; 
      $time .= sprintf ":%02d", $min if grep {/min/} @timeparts; 
      $time .= " $day" if grep {/^day$/} @timeparts;
      $time .= " $month" if grep {/^month$/} @timeparts;
      $time .= " $mday" if grep {/day-of/} @timeparts;
      $time .= " $year" if grep {/year/} @timeparts;
      print header, start_html, p("The time is: $time"), end_html;
}


print header;
print start_html("Digital Clock!"), h1("Digital Clock!");
print start_form(),
      "Show: ",
 # -override means that after the time is given, all the checkboxes are
 # CLEARED!!  Usually, settings given by a user are "sticky" between one
 # call to a script and another call. 
      checkbox_group(-name => 'time_parts',
                     -value => ['hours', 'minutes', 'month', 'day-of-month',
                               'day', 'year'], -override => 1),
      p(), reset(-name=>'Reset'), submit(-name => 'Set'), end_form;

print end_html;