use strict; use warnings; my $form; if ( $ENV{'REQUEST_METHOD'} eq "GET" && $ENV{'QUERY_STRING'} ne '') { $form = $ENV{'QUERY_STRING'}; } elsif ( $ENV{'REQUEST_METHOD'} eq "POST" ) { read(STDIN, $form, $ENV{'CONTENT_LENGTH'}); } else { print "\nInvalid request."; exit; } my %inputs; my ($pair, $key, $value); foreach $pair (split('&', $form)) { if ($pair =~ /(.*)=(.*)/) { # found key=value; ($key,$value) = ($1,$2); # get key, value. $value =~ s/\+/ /g; # substitute spaces for + signs. $value =~ s/%(..)/pack('c',hex($1))/eg; $inputs{$key} = $value; # Create Associative Array. } } my $file = "data.bin"; open (my $IN, "<", $file) or die "$0: Can't open input file $file: $!\n"; my %Params; while (<$IN>) { chomp; if ($_ =~ /^\@Params_/) { my ($key, $value) = split(/=/, $_); $Params{$key} = $value; print "$key=$value\n"; } } close($IN); open (my $FILE, ">", $file) or die "$0: Can't open input file $file: $!\n"; #Clear the file print $FILE "\@Params_name=$inputs{'name'}\n"; my $counter = $Params{"\@Params_visitor"} + 1; print $FILE "\@Params_visitor=$counter"; close($FILE); #$|=1; print "Content-type: text/html\n\n"; print <<"HTML"; Hello World - Result Welcome $inputs{'name'}! You are visitor # $counter. HTML exit;