Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

deputy_doofy

macrumors 65816
Original poster
Sep 11, 2002
1,460
390
I've been trying to do some research on PERL and I have found some basic "programs" to try, such as:
Code:
#!/usr/bin/perl -wT
use strict;

print "hello world.\n";
print "<h2>HOLA</h2>\n";

Now, some pages tell me to save it as a .pl file, some say .cgi file.
Either way, when I try to run it in Firefox or Safari, it simply displays the code as text instead of running it.
Some webpages have told me to run it in the terminal, but that does nothing either.

I am running 10.3.9 and I have never done anything to configure the Apache server (which is probably the problem).

I just feel like I'm never going to figure out PERL (and then PHP) if I can't even figure out how to make a simple print-to-screen sample work. The programming itself will be relatively easy for me, but I need to get the environment working first.

Any and all help is greatly appreciated.
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
I'm not sure what the -wT mean after perl, but I've always used -w and it has worked. For testing though, you need neither of them.

Next run from the terminal:

perl <filename>

It doesn't matter what extension you use.

For it to work in a web browser, you're missing a couple of things. First the Perl script must run as a CGI executable from a web server. Opening the file locally, meaning opening it as a file not through http, will not work.
 

deputy_doofy

macrumors 65816
Original poster
Sep 11, 2002
1,460
390
belvdr said:
I'm not sure what the -wT mean after perl, but I've always used -w and it has worked. For testing though, you need neither of them.

Next run from the terminal:

perl <filename>

It doesn't matter what extension you use.

For it to work in a web browser, you're missing a couple of things. First the Perl script must run as a CGI executable from a web server. Opening the file locally, meaning opening it as a file not through http, will not work.

Ok, I will try that in the terminal. For web browsers, what other settings would I need to make it work as a CGI executable. I know this stuff should all work in OS X, so it's a great place to (try and) learn this stuff. :)
The help is greatly appreciated.
 

inlimbo

macrumors 6502
Jan 29, 2005
411
0
Sydney, Australia
A few things it might be:

Are u sure that is the correct path to perl? i.e. it could be #!/perl/bin/perl
The extension should not really matter. Depends on how ur server is set up. Mine accepts both .pl and .cgi

Have you set the permissions up correctly? i.e 755
Did you upload it in ASCII mode?

Here are some really helpful links
http://www.cgi101.com/learn/ - has some great tutorials/examples. It will help you out. This is how I learnt pearl.
http://perlguru.com/ - discussion forum. They are really helpful!
 

inlimbo

macrumors 6502
Jan 29, 2005
411
0
Sydney, Australia
deputy_doofy said:
I am running 10.3.9 and I have never done anything to configure the Apache server (which is probably the problem).

I just read ur post again. U are right this is probably ur problem. I have no experience running Apache or anything on OS X. I have set up Perl and Apache on my PC. If u have a PC, setting up Perl and Apache is pretty easy. CGI101 has a guide to setting up Perl and Apache on Win XP.

Opps just noticed CGI101 also has a guide for setting it all up on OS X! Check it out. This will solve ur problems im sure! Perl is easy but it is a pain getting over these introductory hurdles. U will love Perl when u get started.
http://www.cgi101.com/learn/connect/mac.html
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
Before worrying about running as a CGI, make sure you can run from Terminal.

The only thing required on Apache is to enable the mod_perl module. You can do this in httpd.conf. Usually the LoadModule and AddModule tags are just commented out, so you can remove those # signs, and restart Apache and you'll be good.

Also, make sure you put your perl files in the cgi-bin directory. In httpd.conf, check for the ScriptAlias directive, and it will show you where cgi programs go. I think it is /Library/WebServer/CGI-Executables by default.

Then, when you get that going, you'll need to add this to the file, so web browsers can interpret it.

Just replace what is in the BODY section:

Code:
print "Content-type: text/html\n\n";
print "<HTML><HEAD>\n"; 
print "<TITLE>CGI Test</TITLE>\n"; 
print "</HEAD>\n"; 
print "<BODY><A HREF=\"http://someplace.com\">Click Here</A>\n"; 
print "</BODY></HTML>";
 

deputy_doofy

macrumors 65816
Original poster
Sep 11, 2002
1,460
390
Thanks for all the great info. I have bookmarked all the pages. I also downloaded PHP and finally got a test program to work. Perhaps I'll get a good jump on perl and php. It would be nice.
My last question for now is based on the configuration page - http://www.cgi101.com/learn/connect/mac.html.

http://localhost/ works for me and I can access the pages at this webserver location in OS X.
However, http://localhost/~doofy does NOT work and gives me the following error:

Forbidden
You don't have permission to access /~doofy on this server.

Apache/1.3.33 Server at d-doofy-computer.local Port 80


Strangely, this error only happens on my powerbook. On the G5, it does work. Any idea what would cause this page to be denied?

Edit: Stupid me. I think I have been having this problem for months due to a permissions problem. Except my own account, which had NO ACCESS, everyone else had READ ONLY. I changed it to read only and it worked. I'm such a Doofy™. :D
 

inlimbo

macrumors 6502
Jan 29, 2005
411
0
Sydney, Australia
belvdr said:
Just replace what is in the BODY section:

Code:
print "Content-type: text/html\n\n";
print "<HTML><HEAD>\n"; 
print "<TITLE>CGI Test</TITLE>\n"; 
print "</HEAD>\n"; 
print "<BODY><A HREF=\"http://someplace.com\">Click Here</A>\n"; 
print "</BODY></HTML>";

Why can't u use the CGI.pm module?
Code:
#!/usr/bin/perl -wT
use CGI qw(:standard);
print header;
print start_html("CGI Test");
print "<a href='http://someplace.com/'>Click here</a>\n";
print end_html;
 

belvdr

macrumors 603
Aug 15, 2005
5,945
1,372
inlimbo said:
Why can't u use the CGI.pm module?
Code:
#!/usr/bin/perl -wT
use CGI qw(:standard);
print header;
print start_html("CGI Test");
print "<a href='http://someplace.com/'>Click here</a>\n";
print end_html;

I guess you can.. I'm used to the old fashioned way.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.