How Do I Print a Variable With a Perl CGI?

The Perl CGI (Common Gateway Interface) module is used to process HTTP requests and responses. You can use the Perl CGI module to print variables to a web page. If you use the Perl here-doc operator, "<<", you can embed the variable directly into an HTML document. The here-doc operator allows you to create the HTML document as if creating a pure HTML document. Variables can be placed inside the HTML code and the Perl interpreter will print the value of the variable.

Instructions

    • 1

      Open a blank document in any text editor.

    • 2

      Type the line

      #!/usr/bin/perl

      use CGI qw/:standard/;

      to start the Perl script and load the standard CGI routines.

    • 3

      Type the command

      my $my_string = "Hello Universe!"

      to create a variable that contains the string "Hello Universe!"

    • 4

      Type the command

      print <<ENDHTML;

      <html>

      <body>

      <p>$my_string<p>

      </body>

      <html>

      ENDHTML

      to print the value of the variable to the web page.

    • 5

      Save the file with the ".cgi" file extension to indicate that it is a CGI script.

Related Searches:

References

Resources

Comments

Related Ads

Featured