#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my $database_file_name = "fake.txt"; print header(); print start_html(-title=>"Search Results"); #Open and read in the file open(DATABASE, "<", $database_file_name) or die "Unable to open $database_file_name: $!\n"; my @input_data = ; close(DATABASE); #Get the supplied search term. my $school_search_term = param("School1"); #The HTML table header my @table_rows = th(["Date", "School 1", "Score 1", "School 2", "Score 2", "Where"]); #Loop through each record, looking for a match. my $num_matches = 0; foreach my $record (@input_data) { my ($id, $date, $where, $school_1, $score_1, $school_2, $score_2) = split(/\|/, $record); if(lc($school_search_term) eq lc($school_1)) { #We've found a match $num_matches++; push @table_rows, td([$date, $school_1, $score_1, $school_2, $score_2, $where]); } } #Print the results table, if necessary if($num_matches) { print table(-caption=>"Search Results", Tr(\@table_rows)); print "Found $num_matches matches", br() } else { print b("I'm sorry, no matches were found"), br(); } #Close the html page print end_html;