class.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";

$number = $formdata{'number'};
%catalan = (1, "un", 2, "dos", 3, "tres", 4, "quatre", 5, "cinc");
%spanish = (1, "uno", 2, "dos", 3, "tres", 4, "cuatro", 5, "cinco");
%french = (1, "un", 2, "deux", 3, "trois", 4, "quatre", 5, "cinc");

if ($number =~/^[1-5]$/) {
	print "<P>You chose the number $number. That number translated into Catalan is <B>$catalan{$number}</B>. In French, it's <B>$french{$number}</B>. In Spanish, it's <B>$spanish{$number}<B>.";
} else {
	print "<P>Sorry, you didn't choose a number between 1 and 5. Try again.";
}