Why is the Perl CGI program showing program code and not output?

CODE - TEST.CGI

#!/usr/bin/perl  
use strict;  
use warnings;  

use CGI::FastTemplate;

my $tpl = new CGI::FastTemplate("/some/directory");  
$tpl->no_strict();  
$tpl->define(main    => "test.htm");  
$tpl->assign(TEST_CONTENT=> "Test");  
$tpl->parse(CONTENT   => "main");  
$tpl->print('CONTENT');  

PATTERN FILE

< html>  
< head>  
< title>TEST< /title>  
< /head>  

< body>  
$TEST_CONTENT  
< /body>  
< /html>

EXPLAIN

Why can't I see the desired output in the browser? When I go to the test.cgi file, all I see is the actual code, not the template. What am I doing wrong?

+3
source share
1 answer

You see the code instead of the output of the program, because you did not configure the web server to run the program, so by default it serves to work with the file as text / regular.

How you configure it depends on the server software you are using. For example, see Apache 2.2 CGI docs .

Secondly, the shebang line is missing. The program should begin with:

#!/usr/bin/perl

/usr/bin/perl - Perl, .

, :

  • use strict; use warnings;. Perl, , .
  • HTML Doctype, quirks. Doctype boilderplate HTML, .
+11

Source: https://habr.com/ru/post/1791059/


All Articles