Perl "hello world"

I’m trying to use perl on my web server (to convert a function from perl to PHP).

Now, there is a working perl webapp on the server that’s running fine, so perl is installed and working.

However, when I try to create my own “hello world” perl script, I keep getting a server error 500.

I’ve uploaded a file named perl.pl into a cgi-bin under a www/mydomain.com/ folder.

I’ve chmoded the perl.pl file to 755.

Here’s the contents of the perl.pl file:

#!/usr/bin/perl

print "hello";

Am I missing something obvious?

With such a simple script, it’s a pretty safe bet the problem isn’t with the print line.

That leaves the “bash”. It’s been a while since I worked with Perl, but the documentation shows

#!/usr/bin/env perl

and I have a file with

#! /local/bin/perl5

The files I wrote used the same as yours, but maybe you need cgi-bin instead of bin ?? Or

#!/usr/local/bin/perl

Hopefully you can find the needed symlink for your host. If you can find a working Perl script, see what it uses.

Nope, neither did the trick.

In any case, I managed to come up with a workaround where I didn’t have to get involved with converting a function from perl to php. It was starting to get really complicated really quickly…

Well Perl is not PHP :wink:
PHP was created specially to do web development, Perl wasn’t.

So when you do a print or an echo in PHP de parser adds some important lines so the webbrowser knows what to do with them.
Perl doesn’t, there you need to add them yourself.

so what you need to do is this:


#!/usr/bin/perl

print "Content-type: text/html\
\
"; 
print "hello";


the extra print line sends the correct Content-type to the webbroswer so he can display all the following print statements correctly.

That’s not very handy… I hear you thinnking.
Wel The perl community wouldn’t be the perl community if they can’t make it easier :wink: you got to love CPAN and the members :smiley:

If you really want to get into using Perl to develop for the web, you should take a look at the CGI module from CPAN. This will make your life easier. It will automaticly include all special processing which otherwise you need to do by hand:

http://search.cpan.org/dist/CGI.pm/lib/CGI.pm

And type perl cgi into google for some nice tutorials :slight_smile:

The articles/tutorials I was looking at didn’t really stress the fact that the content type was a necessary component.

Oh well, now I know. Thanks :slight_smile:

Instead of CGI, check out mod_perl(2) if you’re running Apache… CGI will give you the impression that Perl is too slow for web development : ) Current CGI scripts should work fine with mod_perl.

*edit I noticed Matt’s Script Archive appears in google if you look for “cgi perl”. Avoid that at all costs: it’s outdated enough to destroy worlds! Try to stick with good perl sources like perldoc, CPAN, perlmonks, perl.com, etc.

For the web-specific stuff, you may want an actual framework meant for the web. Catalyst comes to mind, but know it makes heavy use of [url=http://www.iinteractive.com/moose/]Moose (OO-sugar-goodness for Perl). There are others, but my point is that a framework meant for the web should already have considerations for browsers etc built in.