Path to Perl

C

chuck

Hi,

New to Linux and Apache and Perl so I appreciate any help i can get.

I have a user who needs to move his perl scripts from his Windows
development machine to our Linux web server. How can I easily change the
path to all the perl scripts that will get transfered over ? Or is there
another alternative such as adding an environment variable for the "apache"
user ?

Thanks
 
R

RedGrittyBrick

chuck said:
Hi,

New to Linux and Apache and Perl so I appreciate any help i can get.

I have a user who needs to move his perl scripts from his Windows
development machine to our Linux web server. How can I easily change the
path to all the perl scripts that will get transfered over ? Or is there
another alternative such as adding an environment variable for the "apache"
user ?

Your subject says "Path to Perl" but the body says "path to all the perl
scripts". Those are two completely different things. Assuming you mean
the former and are referring to the so-called shebang line:

perl -p -i -e 's|^#!perl|#!/usr/bin/perl| if $.==1;' *.pl


Presumably the user used no unusual modules and didn't make explicit
references to platform specific filesystem locations ("c:\") etc etc.
 
R

RedGrittyBrick

chuck said:
Or is there
another alternative such as adding an environment variable for the "apache"
user ?

Oops yes, IIRC the apache config file specifies what happens when
someone requests a URL that points to a .pl or .cgi file.

I'd be surprised if your Apache service wasn't already configured for
this but YMMV.
 
C

chuck

What I need to do is change the first line of all the scripts from
"c:/perl/..." to "#!usr/bin/perl"

or get the system into look in /usr/bin/perl without changing the scripts by
using an environment variable.
 
G

Gunnar Hjalmarsson

Sounds like CGI scripts to me ...
Just use "#!/usr/bin/perl" - Windows uses its file-type associations to find
the Perl binary anyway, so it won't care.

.... and if so, that's not true. CGI scripts need the correct path to
perl also on Windows.

OTOH, personally I have a symlink in C:/usr that points to the directory
with perl.exe, and that directory is conveniently named 'bin'.
Consequently, #!/usr/bin/perl works just fine for my CGI scripts on Windows.
 
R

RedGrittyBrick

chuck wrote:

What I need to do is change the first line of all the scripts from
"c:/perl/..." to "#!usr/bin/perl"

perl -p -i.bak -e 's|^\S+|#!/usr/bin/perl| if $.==1;' *.pl

Untested. Should retain flags (e.g. #!c:/perl/bin/perl.exe -w).
Assumes the old (Windows) path to perl contains no spaces.
Keeps a copy of original versions of scripts with filename suffix ".bak".

You could also use awk sed or some similar tool that you are more
familiar with. I guess you are not familiar with these since you asked
the question. Which suggests you are not very familiar with Unix/Linux.
If so, do above when logged in as ordinary user (not root), I'd put
files in a newly created directory before working on them.
or get the system into look in /usr/bin/perl without changing the
scripts by using an environment variable.

I'd configure Apache, forget environment variables.
 
C

chuck

RedGrittyBrick said:
chuck wrote:



perl -p -i.bak -e 's|^\S+|#!/usr/bin/perl| if $.==1;' *.pl

Untested. Should retain flags (e.g. #!c:/perl/bin/perl.exe -w).
Assumes the old (Windows) path to perl contains no spaces.
Keeps a copy of original versions of scripts with filename suffix ".bak".

You could also use awk sed or some similar tool that you are more
familiar with. I guess you are not familiar with these since you asked
the question. Which suggests you are not very familiar with Unix/Linux.
If so, do above when logged in as ordinary user (not root), I'd put
files in a newly created directory before working on them.


I'd configure Apache, forget environment variables.

Thanks. Ended up using sed, after figuring out the escape characters that
is.
 
G

Gretch

In
chuck said:
What I need to do is change the first line of all the scripts from
"c:/perl/..." to "#!usr/bin/perl"

Please don't top-post.

The relative path "usr/bin/perl" isn't what you want to do. You'll have
better portability with

#!/usr/bin/env perl
 
E

Eric Schwartz

Thrill5 said:
My question would be why is he using a shebang for the perl path on a
windows machine in the first place?

To pass along command line flags like -T?

-=Eric
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top