cityinfo.cgi

 


#!/usr/bin/perl

@pairs = split(/&/, $ENV{'QUERY_STRING'});

foreach $pair (@pairs)
{
    ($key, $value) = split (/=/, $pair);
    $key =~ tr/+/ /;
    $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~s/<!--(.|\n)*-->//g;

    if ($formdata{$key})
    {
        $formdata{$key} .= ", $value";
    }
    else
    {
        $formdata{$key} = $value;
    }
}


print "Content-type: text/html\n\n";

if ($formdata{'infotype'} eq 'time') {

	%zones=('Hartford', 5, 'Dallas', 6, 'Denver', 7, 'Eureka', 8);
	$city=$formdata{'city'};

	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(time);

	$hour = $hour-$zones{$city};

	if ($hour <= 0) {
		$hour = $hour +24;
	}
	
	$min=sprintf("%02d", $min);
	$sec=sprintf("%02d", $sec);

	print "<P>The local time in $city is $hour:$min:$sec";

} 	else {
	print "<P>I haven't written that part of the program yet. Sorry.";
	}