1752307 Members
5359 Online
108786 Solutions
New Discussion юеВ

Re: Which perl question

 
4ldo
Occasional Contributor

Which perl question

Hi all,

In hp-ux if i start a perl program like "#!/usr/local/bin/perl" and there is no /usr/local/bin/perl binary (or a link to binary), it will go on search my $PATH for perl and execute the program. If I try the same on my laptop (Linux) then it will inform me that there is no interpreter (no /usr/local/bin/perl- even though perl is in my path in /usr/bin) and halt ( which makes sense to me). Do you know why this is happening?

Thanks in advance : )

BR-s,
Alex
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor

Re: Which perl question

If there is no /usr/local/bin/perl the script should fail regardless of the platform. I suspect that what is really happening is that the "shebang" line is not the very first line of your script with no leading whitespace. In that case, the shebang becomes a comment.

In any event, generally the least evil approach that I have found is to shebang all perl scripts as:
#!/usr/bin/perl -w
on all platforms. Then for each platform, I create a symbolic link from the actual location to /usr/bin/perl, e.g.
ln -s /usr/local/bin/perl /usr/bin/perl

Once that link is created on each target platform, /usr/bin/perl works every time. This convention even works on Windowes because Windows doesn't observe the shebang convention and treats the line as a comment.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Which perl question

Hi Alex:

To aid in locating your perl binary, you could do:

# whereis perl

Then, as Clay suggests, create any necessary symbolic link from '/usr/bin/perl' to the installed binary and use the standard link as your standard interpreter line.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Which perl question

One clever trick that I've seen to execute an "interpreter" anywhere in your path is:
#!/usr/bin/env perl

Unfortunately it doesn't appear to let you put any arguments on that line.
dirk dierickx
Honored Contributor

Re: Which perl question

indeed, 'env; used to be a good solution for these kind of problems, but then again, 'env' is not installed on all systems either...

so in the end i just made sure all systems had a link at the same place to the real location.
4ldo
Occasional Contributor

Re: Which perl question

Thanks a lot for your comments guys.. No have it all clear : )

Cheers Alex
James R. Ferguson
Acclaimed Contributor

Re: Which perl question

Hi Alex:

We're glad you have found help here. Please read:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...