use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi = CGI->new; my %form = $cgi->Vars; print $cgi->header; 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_fname=$form{'fname'}\n"; my $counter = $Params{"\@Params_visitor"} + 1; print $FILE "\@Params_visitor=$counter"; close($FILE); print $cgi->start_html('Hello World'), $cgi->p("Welcome $form{fname}!"), $cgi->p("You are visitor # $counter"), $cgi->end_html; exit;