SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)

    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:

    Code:
    #!/usr/bin/perl
    
    print "hello";

    Am I missing something obvious?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,187
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    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
    Code Perl:
    #!/usr/bin/env perl
    and I have a file with
    Code Perl:
    #! /local/bin/perl5
    The files I wrote used the same as yours, but maybe you need cgi-bin instead of bin ?? Or
    Code Perl:
    #!/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.

  3. #3
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    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...
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  4. #4
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well Perl is not PHP ;-)
    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:

    Code Perl:
    #!/usr/bin/perl
     
    print "Content-type: text/html\n\n"; 
    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 ;-) you got to love CPAN and the members :-D

    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
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  5. #5
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    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
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    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 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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •