http directive to exec perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

At the beginning of each perl cgi script is the #! line. I'm assuming that
this is an http directive that executes perl and indicates thedirectory in
which perl is found.

I'm developing scripts for a client. The problem is that he is using a
different web host than I am, and perl is found in different directories,
so I need to use different #! directives at the beginning of the scripts.

I don't want to have to change the scripts when I move them from my host
to the client's host. Is there a '#if' '#else' type of directive pair, and
if there is, what is the syntax and what test could I use to have the
script know whether it's running on my host or the client's host?
(Possibly the environment, $ENV.)

Is there another way to accomplish this?


Re: http directive to exec perl writes:

Quoted text here. Click to load it

It's a directive to the underlying operating system.

Quoted text here. Click to load it

Can you just make a symlink on one server or the other, so there's
some path that will work on both?

If not, there's some tricks in the perlrun(1) manpage that may help:

     Parsing of the #! switches starts wherever "perl" is
     mentioned in the line.  The sequences "-*" and "- " are
     specifically ignored so that you could, if you were so
     inclined, say
         #!/bin/sh -- # -*- perl -*- -p
         eval 'exec perl -wS $0 $'
             if $running_under_some_shell;
     to let Perl see the -p switch.
     A similar trick involves the env program, if you have it.
         #!/usr/bin/env perl

Another possibility is to simply use another Perl script to
automatically fix the "shebang" line.


Re: http directive to exec perl

On Thu, 16 Sep 2004, Scott W Gifford wrote:

Quoted text here. Click to load it

Usually, yes.  But in the case of Windows Apache, the underlying OS
wouldn't know the shebang line from a hole in the ground. So I
think we might need a bit more context.


Re: http directive to exec perl

Quoted text here. Click to load it

Why assume? Any introductory resource on Perl explains what that line

Quoted text here. Click to load it

No, it does not have anything to do with HTTP.

Quoted text here. Click to load it

* Write an install script that actually writes the correct path to Perl
in each script as part of the installation process.

* Modify your web server's configuration so as to use a specific
interpreter rather than the one specified in the script.

This is all OS and server software specific, you might want to try a more
relevant group.


Site Timeline