Here's what I have so far:
#!/perl/bin/perl -w
# text analyzer
use strict;
use CGI qw/:standard/;
print header();
print start_html("This will count your words");
# check for param, if params present, then form is submitted
if(param()) {
my $fname = param ('fname');
if(!$fname){
dienice("You did not enter your name, please click the back bu
+tton\n");
}
# code for assigning variables for each param
# get all other data and check if present, otherwise dienice
my $email = param('email');
if(!$email){
dienice("You did not enter your email, please click the back b
+utton\n");
}
my $text2count = param('text2count');
# get a text array from text
my @textarray = get_text_array($text);
# make a hash out of this array @textarray
my %texthash = get_counting_hash(@textarray);
# after get all of the values needed, print out the content for th
+e result:
print <<EOHTML1;
# I know I need to do a foreach loop here with a table tag before
+the loop and and ending table tag after the loop
EOHTML1
} else {
#print the HTML form out here so we can get the name,email and the
+ text
print <<EOHTML;
# THIS IS WHERE THE FORM WILL GO - LEFT THIS OUT TO CHOP CODE
+- This I have completed
EOHTML
}
print end_html(); # end of the page right here
# subroutine to die - provided by our teacher
sub dienice {
my ($s) = @_;
print $s, "\n";
exit(1);
}
# make a text array out of the plain text
sub get_text_array {
return split(/ /, $_[0]);
}
# building a hash counting words from an array of words
# the keys are the words
# the values are the number of occurrences of that word in the array
sub get_counting_hash {
my @wordArray = @_;
my %wordHash = ();
# I think I need some code here?
return %wordHash;
}
I'm hazy on the foreach loop to make the table and also on the subroutine get_counting_hash...