http directive to exec perl

D

develop

Hi,

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?

Thanks,
Dan
 
S

Scott W Gifford

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.

It's a directive to the underlying operating system.
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.

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 ${1+"$@"}'
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.

----ScottG.
 
A

A. Sinan Unur

Hi,

At the beginning of each perl cgi script is the #! line. I'm assuming

Why assume? Any introductory resource on Perl explains what that line
does.
that this is an http directive that executes perl

No, it does not have anything to do with HTTP.
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?

* 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.

Sinan
 
A

Alan J. Flavell

It's a directive to the underlying operating system.

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.

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top