Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I wrote my first perl program 10 minutes ago:
--first.pl--:
  #!/usr/bin/perl
  print "Hello, world!\n";
I moved it on our Apache server, I gave the rights:
  chmod 755 first.pl
and I wanted to execute it:
  ./first.pl
but it is didn't work. Why? Please, help me!
(If I execute it by
  perl first.pl
then it works.)

Thanks: A helpless girl.

Replies are listed 'Best First'.
(Ovid) Re: A very beginner problem
by Ovid (Cardinal) on Feb 11, 2002 at 19:50 UTC

    This implies that you actually have Perl on the box, but your shebang line is not pointing to the Perl interpreter. At the command line (assuming you're using a *nix type system), type which perl. This will tell you the location of your Perl interpreter and you'll want to update your shebang to match this information.

    If you're working on a Windows box, ./first.pl is probably not legal syntax and you'll either have to have a newer version of Windows that recognizes the file extension from the command line (Win2K does this, for example), or you will always have to type perl first.pl to get it to run.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: A very beginner problem
by LukeyBoy (Friar) on Feb 11, 2002 at 20:23 UTC
    Looks like you forgot the content type header, which Apache needs to be able to send to the client browser. Change the script to this:
    #!/usr/bin/perl print "Content-Type: text/plain\n\n"; print "Hello, world!\n";
      LukeyBoy is right and I would like to expand on what he said. When sending information via a web server the server has to know what kind of content is being sent and verifies that the outgoing content has the correct header on it. In the case of static .htm(l) it adds the correct header for you since it has the correct mime mapping and the content is not being processed by a forgein handler. So adding the line that LukeyBoy specified tells apache that the content is HTML and should solve your Internal Server Error problem.
Re: A very beginner problem
by PrimeLord (Pilgrim) on Feb 11, 2002 at 19:47 UTC
    Your perl executable may not be in /usr/bin try using #!/usr/local/bin/perl or do a locate perl and find the path to the perl executable. If that doesn't resolve your problem try posting the error message you are getting when your program won't run.