An example of using QUERY_STRING. : Environment Variables « CGI « Perl






An example of using QUERY_STRING.

    

# Name this Perl script file as test.pl

use warnings;
use strict;
use CGI qw( :standard );

my $query = $ENV{ "QUERY_STRING" };

print header(), start_html( "QUERY_STRING example" );
print h2( "Name/Value Pairs" );

if ( $query eq "" ) {
   print 'Please add some name-value pairs to the URL above. ';
   print 'Or try <a href = "test.pl?name=Joe&age=29">this</a>.';
}
else {
   print i( "The query string is '$query'." ), br();

   my @pairs = split ( "&", $query );

   foreach my $pair ( @pairs ) {
      my ( $name, $value ) = split ( "=", $pair );
      print "You set '$name' to value '$value'.", br();
   }
}

print end_html();

   
    
    
    
  








Related examples in the same category

1.Display CGI environment variables
2.Viewing Environment Variables in a CGI Script
3.CGI Environment Variables
4.Learn about the server for a CGI request
5.Program to display CGI environment variables.
6.$ENV{'HTTP_USER_AGENT'}, $ENV{'SERVER_PROTOCOL'}, $ENV{'HTTP_HOST'}
7.Get and display the browser type by referencing HTTP_USER_AGENT
8.Server Environment Values
9.CGI request-related environment variables
10.CGI server-related environment variables
11.CGI client-related environment variables
12.HEADER DESCRIPTION
13.Display all values in env
14.Determining the User Agent and Printing the Appropriate Result
15.CGI Environment Variables (Must Be Uppercase)
16.CGI environment variable