#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);

my $sequence = "";

# read data from our data.txt file (with our own demo sequence)
open( INFILE, "data.txt");
                while(<infile>){
                                my $line = $_;
                                chomp $line;
                                $sequence = $sequence . $line;
                }
close(INFILE);


# create a CGI object in order to create the HTML file
my $q = new CGI;


# read the parameters sent thru the form and do necessary initializations
my $new_seq = $q->param("sequence") || "No Sequence";
$new_seq =~ s/[\s\n\t]+//g unless $new_seq =~ /No Sequence/;
$new_seq = "No Sequence" if $new_seq =~ /[^AaCcTtGg]/;
$sequence = $new_seq unless $new_seq =~ /No Sequence/ ;
$sequence = uc $sequence;

# start printing the HTML file
print $q->header();

# print the sequence that has been pasted
$q->print("<html><head><title>Sequence Results </title></head><body onLoad='javascript:focus()'>");
$q->print("<table border=0 cellpadding=3 cellspacing=2 width=\"700\"><tr width='650'><td width=\"650\">");

my $pp = $sequence;
$pp =~ s/(\w{40})/$1\n/g;
$q->print("$pp<br>\n");
undef $pp;
$q->print("</td></tr></table>");

# parameters initialization
my $size = length $sequence;

# print the length

&showLength($size) if ($actions->{'length'}->[0] || $actions->{'all'}->[0]);

# close the HTML file
$q->print("</body></html>");


sub showLength{
                my $size = shift;
                $q->print("The length of the sequence is: $size<br>\n");

                return;
}