When a CGI script is called several environment variables are set and you can access these from Perl. To see what some of the environment variables are you can try the example perl CGI script at
This program simply accesses Perl's associative %ENV array to print out the values of the environment variables. You can have a look at the source of this program to see how it accesses the variables.
Possibly the most useful of these environment variables is the QUERY_STRING variable. In the above example this was the empty string, but if we append, say,
?somethingonto the end of the URL then the string after the ? gets put into the environment variable QUERY_STRING. Try opening the following URLs. The first one is the same as we used above.
The endless document is called initially with QUERY_STRING equal to 1, and anchors to the previous and next pages have their query string calculated from this. You may also like extend the use of QUERY_STRING so that instead of just containing the intended page number it also contains the value of the last page visited.