#!/usr/bin/perl print qq{Content-type: text/html\n\nCGI Processor}; %images = ( "One" => "http://www.cs.indiana.edu/dept/img/lh01.gif", "Seven" => "http://www.cs.indiana.edu/dept/img/lh07.gif", "Eight" => "http://www.cs.indiana.edu/dept/img/lh08.gif", "Nine" => "http://www.cs.indiana.edu/dept/img/lh09.gif" ); %next = ( "One" => "Seven", "Seven" => "Eight", "Eight" => "Nine", "Nine" => "One" ); %prev = ( "One" => "Nine", "Seven" => "One", "Eight" => "Seven", "Nine" => "Eight" ); &readParse; # [1] read, parse and ... $pic = $in{pic}; # [1] name (the state) # [1] is called "retrieve state" if ($pic eq "") { # if state is empty $pic = "One"; # initialize it } else { # otherwise (state is not empty, this is an existing user) # print "
($pic)
"; $action = $in{action}; # see what they want if ($action eq "next") { # if they want the next picture $pic = $next{$pic}; # set the state to next picture } else { # otherwise if ($action eq "previous") { # if they want the previous picture $pic = $prev{$pic}; # we give them that } else { } # otherwise we don't do anything } } # so now we report, store the state and get ready for more input print qq{
}; print qq{}; sub readParse { $user = $ENV{"QUERY_STRING"}; @pairs = split(/&/, $user); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair, 2); $value =~ s/%(..)/chr(hex($1))/ge; $in{$name} = $value; } }