#!/usr/bin/perl

# This CGI program gets space separated numbers, adds them and displays the 
# sum

&ReadGetData(*datain);	# The subroutine gets the data in the string "datain"

    print &PrintHeader;
    print("<body>");
    @parts=split(/=/,$datain);		#	These two lines separate the numbers 
					#	into an	array "numbers"
    @numbers=split(/\+/,@parts[1]);	#
	
	$sum=0;
		
    for($i=0;$i<@numbers;$i++){		# 	Add the numbers in a loop
    	$sum+=$numbers[$i];
    }

    print("<center> The sum of the numbers is $sum </center>");
    print("</body>");
	

sub PrintHeader
{
	print "Content-type: text/html\n\n";	# This is the header which indicates that the 
						# incoming text is HTML
}


sub ReadGetData
{
	local(*query_string)=@_;

	$query_string=$ENV{"QUERY_STRING"};

	return 1;
}	


