#!perl ??

J

J Krugman

I've seen code that starts with the line

#!perl

but when I try the same thing myself, I get a 'bad interpreter'
error. And yet, something like this:

% perl -le 'print "hello"'

works perfectly. What do I have to do to use #!perl (instead of
a fully qualified path) as my shebang line?

TIA!

jill
 
T

Tintin

J Krugman said:
I've seen code that starts with the line

#!perl

Which does nothing on Windows systems, or the below error on Unix systems.

Note, that any perl switches will be recognised on Windows systems.
but when I try the same thing myself, I get a 'bad interpreter'
error.

As to be expected on Unix systems. You need to use the absolute path to
perl.
And yet, something like this:

% perl -le 'print "hello"'

The shell searches the directories in the PATH environment variable to find
where perl is.
works perfectly. What do I have to do to use #!perl (instead of
a fully qualified path) as my shebang line?

Either use Windows, or call the script directly with perl, eg:

perl yourscript.pl
 
T

Tad McClellan

J Krugman said:
I've seen code that starts with the line

#!perl


If run on Windows, you could put command line switches on that
line and they would be recognized.

but when I try the same thing myself, I get a 'bad interpreter'
error.


If run on *nix, you get that error message.

What do I have to do to use #!perl (instead of
a fully qualified path) as my shebang line?


Why do you think you want to use #!perl (instead of a fully
qualified path) as your shebang line?

That is, what problem are you hoping to overcome by being able
to do what you've asked?

If we knew that, we might be able to suggest an alternative.
 
J

J Krugman

Why do you think you want to use #!perl (instead of a fully
qualified path) as your shebang line?

It's just laziness on my part :) . I want be able to download Perl
scripts and run them as is (after changing permissions):

% wget -q -O perl_script.pl http://url.to.some/perl_script.txt && \
chmod +x perl_script.pl && \
perl_script.pl

without having to fuss with firing up vi and fixing the first line.
(Of course, the above is something I'd do only with a script that
I was confident was safe.) Arguably I could just use

% perl perl_script.pl

but this solution is suboptimal because often a Perl script will
have switches on the first line that are critical to its operation,
so I'd have to first inspect that first line and replicate the
switches in my own invocation. This is a minor pain with simple
switches like '-l', but it because increasingly more of a pain as
the complexity of the switches increases.

As I said, just another case of programmerly laziness...

jill
 
A

Anno Siegel

J Krugman said:
[...]

Arguably I could just use

% perl perl_script.pl

but this solution is suboptimal because often a Perl script will
have switches on the first line that are critical to its operation,

Perl is friendly enough to parse those switches, even when invoked
explicitly, so don't worry about that.
As I said, just another case of programmerly laziness...

....supported by Perl, so just go along with your intuition.

Anno
 
J

J Krugman

In said:
Arguably I could just use

% perl perl_script.pl

but this solution is suboptimal because often a Perl script will
have switches on the first line that are critical to its operation,
Perl is friendly enough to parse those switches, even when invoked
explicitly, so don't worry about that.
...supported by Perl, so just go along with your intuition.

Thanks!!!

jill
 
A

A. Sinan Unur

Did Jill make the comments below? No.

Please use a more effective quoting style and avoid misattributions.
Search this page

http://savage.net.au/Perl/html/upgrade-perl-apache.html

for /usr/bin/perl and you'll what to do under Windows for the she-bang
line.

1. You completely missed the point of Jill's post.

2. Her question was not about setting up Apache and Perl on Windows.

3. Even if it were, the answer you pointed to is not that great. See
http://httpd.apache.org/docs-2.0/mod/core.html#scriptinterpretersource
for a better way.


Sinan
 

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

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top