GSP - A simple example : perl version

 GSP Home  Previous  Next

Last single page example : perl handling.

the GSP source page : perl.gsp 

<html>
<%@ language="perl"
    mime type = "text/html"
    %>
<%!
 #
 # a comment to test the ! tag
 #
%>
<body>
<%
    $hello="Hello world";
    $a=20;
    $b=22;
    $c=$a+$b;
%>
<h1><%=$hello%></h1>
<p>The answer is <%=$c%></p>
</body>
</html>

Invoking GSP to produce the cgi perl script 

bash# gsp -o gsp-perl.pl -m perl.gsp

This command will produce one file :

gsp-perl.pl

#!/usr/bin/perl

#
# a comment to test the ! tag
#
sub perl_gsp {
print "Content-Type: ";
print "text/html";
print "\n\n";
print "<html>\n";
print "\n";
print "\n<body>\n";

    $hello="Hello world";
    $a=20;
    $b=22;
    $c=$a+$b;
print "\n<h1>";
print $hello;
print "</h1>\n<p>The answer is ";
print $c;
print "</p>\n</body>\n</html>\n";
}

$defaultPage="perl.gsp";
$requestedPage=$ENV{PATH_INFO};
if ($requestedPage eq "") { $requestedPage=$defaultPage; }
$firstChar=substr $requestedPage,0,1;
if ($firstChar eq "/") { $requestedPage=substr $requestedPage,1; }
GSPPAGESELECT: {
if ($requestedPage eq "perl.gsp") {perl_gsp; last GSPPAGESELECT;}
}


Ready to use ! 

Just copy it to your http server cgi-bin folder.

 début de page  GSP Home  Previous  Next last update 01/18/2004 - 17:27