Installing Perl

antar

Registered
What type of Mac Os needs to work w perl?
Client or server? Developer Tools is necessary?
Which version? I've just modified httpd.conf
and tried from Explorer with test.cgi
and it run, but only if the dir is: #!/bin/sh
if I set #!/usr/bin/perl nothing works;
if I run hello.pl from terminal it works;
in terminal command which perl is /usr/bin/perl.
To edit script I use Xperl 1.2.
I don't understand, could you help me?
iMac 800-512Mb - OSX 10.1.4 client - WebSharing on
 
i would say that perl is already installed, (as it should be. it comes with OSX client and server).

if you can execute the script from the command line, then i can think of no reason why apache should not also be able to execute it.

things to make sure of: the file is chmodded to executable (chmod 755 script.pl), the file is in the webservers cgi executable directory (mv script.pl /Library/WebServer/CGI-Executables/)

if those are satisfied, then i don t understand either. can you check the error log for apache? it might provide some clues: /var/log/httpd/error_log
 
looks like testuser got his reply in while i was drafting mine, and it s more comprehensive. so sorry about the redundant post.
 
now it's all good, the script

#!/usr/bin/perl -w
print "header";

write "header" in terminal, and

#!/usr/bin/perl -w
use CGI qw:)standard);
use strict;
print header;
print "<b>hello, World!</b>";

write "hello, World!" in a browser with
http://localhost/cgi-bin/hello.cgi

now I continue to learn Perl, but I have a question, why this script run only in browser:

#!/bin/sh
echo Content-type:text/html
echo
print "Hello"

and not so?

#!/usr/bin/perl -w
echo Content-type:text/html
echo
print "Hello"
 
well you can do it that way. don t use echo, it is not a perl command, but the point is that the HTTP specification expects you to declare what type of content you are transfering. text/html in this case.

if you import the CGI perl module, the print header; will print this line. if you do not, then you can use
Code:
print "Content-type: text/html\n\n";
. this is equivalent to
Code:
echo Content-type:text/html
echo

it all amounts to the same thing. this line is part of the http protocol, so it doesn t matter how you print it, but you have to print it if you want to page to display. it is not necessary for shell scripts, only cgi scripts.
 
Back
Top