#!/usr/bin/perl -T

use strict;
use CGI;

# create a new form to display results
my $form = CGI->new();

# get the list of selected boxes
my @boxes = $form->param('box');

# create the results page
print $form->header( "text/html" ),
  $form->start_html( -title	=> "Results"),
  $form->h1( "Chosen Boxes:" );

# open a file to write the results to
open(OUTF, ">checkedBoxes.dat") or
  dienice("Can't open checkedBoxes.dat for writing: $!");;

# show which boxes were selected
foreach my $box (@boxes) {
  print $form->p("$box");
  print OUTF "$box\n";
}

# close that html
print $form->end_html;

# close the file
close(OUTF);

sub dienice {
  my($msg) = @_;
  print "<h2>Error</h2>\n";
  print $msg;
  exit;
}
