#!/usr/local/bin/perl
&decode_param;
#use CGI::Simple;

print "Perl...<br>\n";
# decode the parameter on the command line
#$CGI = new CGI::Simple;
#$accountmngt  = $CGI->cookie('accountmngt');

foreach $form (keys %FORM) {
    print "$form $FORM{$form}\n<br>";
}


#foreach $param ($CGI->param) {
#    $FORM{$param}= $CGI->param($param);
#    print "Perl $param $CGI->param($param)<BR>\n";

#}


print <<EOF;
<form method=GET action="">
un param <input type=text name=toto>

deux param <input type=text name=tutu>

<input  type=hidden name=chut value=123>
<input type=submit>
</form>



EOF

sub decode_param {
    # decode the parameter on the command line

    if ($ENV{'REQUEST_METHOD'} eq "POST") { # it should be GET for our case
	$res=read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # POST method
    } else {
	$buffer= $ENV{'QUERY_STRING'}; # GET method
    }    

    # do the little cleaning as usual
    # each argument is saved in @argv, number of argument is in $argc
    my @pair = split(/&/, $buffer);

    foreach (@pair) {
        ($name, $value) = split/=/;
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	if ($name =~ /\.x$/) {
	    $name=$`;
	}
        $FORM{$name} = $value;
    }
}
