Quantcast
Viewing latest article 7
Browse Latest Browse All 8

The CGI Difference

The CGI Difference

CGIs process input differently than old Perl scripting does – and this, my friends, is the only difference you’ll find between the two. Once the CGI scripts process the input, it becomes data, which is treated pretty much the same way by both CGI and Perl scripts. CGI input can be retrieved in two different ways:”get” and “post.” If you’re absolutely sure what type of input you’ll be getting, then you only have to use one type of input retrieval. But if it’s the least bit possible that whoever writes the form won’t mark the input type correctly (and really, who knows what they’ll do), then you have to catch all the possible types of answers. This involves a simple two-step process, handled with an if/else statement.

    if ($ENV{'REQUEST_METHOD'} eq "GET") {



    		$in = $ENV{'QUERY_STRING'};



    	} else {



    		$in = <STDIN>;



    	}


This statement asks the server if the request method (the way in which the server gave you the information) is “get.” If so, the script will read the information from the Query String into a variable called $in. Otherwise, it’ll read it in through standard input just like it would a normal Perl script.


Viewing latest article 7
Browse Latest Browse All 8

Trending Articles