Why is Perl5 getting invoked here? 
Author Message
 Why is Perl5 getting invoked here?

Here's an oddity I hope someone can explain.  I installed Perl5 here
a week ago.  I'm not the sysadmin so I installed it off in a user
directory somewhere.  Okay, so far so good.

Today I wanted to show a co-worker the TkPerl de{*filter*}.  I set the
PERL5DB environment variable, then invoked one of my Perl5 scripts with:

    wildebeest % setenv PERL5DB 'BEGIN{require Tkperldb}'
    wildebeest % /bin/perl -d tgrep

The de{*filter*} came up, and there was the appropriate oohing and ahing.

Now, my question is, *WHY* did the de{*filter*} come up in the first
place?  As I said, I'm not a sysadmin. /bin/perl is version 4.036,
not 5.000!  Does Perl4 read the script's initial "#!" line, evaluate
it, and invoke that interpretter with the command-line options given?
Some experimentation shows that this does seem to be the case.  But
is it really desirable?  Say I wanted to test this script against two
different versions of Perl, to make sure it would run both under Perl4
and Perl5 (for porting to other environments, say, where the Perl5
interpretter isn't installed).  I'd have to edit the file to fix the
initial line for either version, rather than just invoking the proper
version on the command line.  I'd also have to edit the file to fix the
"#!" line if it pointed to a nonexistent path, rather than simply saying
"perl foobar".

This is on a Sparc running SunOS 4.1.3, if it makes any difference.

--

You know, this job would be a lot easier using perl.



Wed, 30 Apr 1997 00:17:02 GMT  
 Why is Perl5 getting invoked here?

Quote:
> Now, my question is, *WHY* did the de{*filter*} come up in the first
> place?  As I said, I'm not a sysadmin. /bin/perl is version 4.036,
> not 5.000!  Does Perl4 read the script's initial "#!" line, evaluate
> it, and invoke that interpretter with the command-line options given?
> [ ... ]

I second the request for more info about the rules involving '#!'.

A month or so ago I asked what rules Perl uses when looking at the
'#!' line.  No one ever answered me, but instead, I got a number of
replies and email messages with people telling me that '#!' is handled
in the Unix kernel and not Perl.  I spent the rest of my time on this
thread in a somewhat grueling exercise to prove to people that yes,
Perl does indeed do some special processing of the '#!' line
... although as to this day, I am still unsure exactly *what*
processing is actually done by Perl, and under what conditions.

I'd like to request that PLEASE (!!!) don't try to answer this by yet
another series of posts stating that Perl doesn't look at the '#!'
line, and that it's really the Unix kernel.  Yes, the Unix kernel
looks at '#!'  BUT SO DOES PERL!!!  Really.  No kidding.  Definitely.
Honest.

Can ANYONE out there state the exact rules that Perl uses for
processing the '#!' line? ... i.e., under what exact circumstances is
this done, what command-line flags affect this, etc. etc. ???

Thanks in advance.

--
Lloyd Zusman            01234567 <-- The world famous Indent-o-Meter.

   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject:
                    mail-request public-key



Wed, 30 Apr 1997 10:14:24 GMT  
 Why is Perl5 getting invoked here?


Quote:

>A month or so ago I asked what rules Perl uses when looking at the
>'#!' line.  No one ever answered me,

[...]

Yes, I followed that thread with discomfort, as I was too busy at that
time to answer it. As the harsh November days lend themselves to RTFS,
I'm bending my head upon toke.c and there I find (line 1277ff):

If you're not in an eval and the script is called by something
containing "perl" and the #! line does not contain "perl", then perl
lets the named program execute. So if you have the script

#!/bin/sh
echo foo

and call that script with `perl script', perl leaves the shell alone
with it. The shell then does the `echo foo'.

O.K. But if you call the script

#!/usr/local/bin/perl4.036

with `perl5.000 script', then perl5 will execute it, as "perl" is
contained in the #! line. Likewise, if you call

#!/bin/sh -- #perl
echo foo

by giving `perl script', you end up with

Can't call method "echo" in empty package "foo" at script line 2.

which is a message from perl, as you probably recognize.

Now let's go to line 1306 of toke.c, where the command-line arguments
are processed. Be aware, that this only happens, if the #! line
contains the string "perl -" (Note; only one blank allowed!). All
switches except n, p, and d are processed in a rather straight manner.
Lets assume a script

#!/no/where/could/ever/be/found/perl -l
print "foo";

and call that as `perl script'. The -l switch will be recognized, and
we get the trailing newline. Now let's try the following:

#!/bin/sh -- # perl -l
print "foo"

SAME RESULT!

And what about the n, p, and d switches? They deserve special
treatment by the parser, but perl ends up processing the script as if
they had been present on the command line. E.g.

#!/usr/bin/perl -d
print "foo"

gives us the de{*filter*}, even called as `perl script'. I'd say, these
three switches don't deserve special mentioning here, they just work
intuitive.

We would certainly be able to fool the logic. What would

#!/usr/bin/perl -l -- #perl -n
print "foo"

give you? It gives us the -l switch, not the -n. Consider adding some
blanks:

#!/usr/bin/perl     -l -- #perl -n
print "foo"

Now the script is processed with the -n switch, but without the -l.

That's all!

--andreas



Thu, 01 May 1997 19:48:09 GMT  
 Why is Perl5 getting invoked here?
[ This reply is publicly posted to comp.lang.perl and also emailed
  privately. ]


Quote:


>> A month or so ago I asked what rules Perl uses when looking at the
>> '#!' line.  No one ever answered me,
> [...]
> Yes, I followed that thread with discomfort, as I was too busy at that
> time to answer it. As the harsh November days lend themselves to RTFS,
> I'm bending my head upon toke.c and there I find (line 1277ff):

> [ ... excellent description of Perl's rather complex handling of '#!'
>       deleted to save net bandwidth ... ]

Ahhhhhhhhhh! <sigh of relief and joy>

I *finally* got the answer I was looking for.  Thank you *very* much
for this extremely useful information.  I assume that this excellent
description of Perl's handling of '#!' is now, even as I post this
reply, being feverishly inserted into the FAQ or into Perl's "pod"
pages ...  :):)

I guess it's time to dive into toke.c (at least now I know what source
file to look in).

Quote:
> That's all!

<much publicly stated appreciation>

--
Lloyd Zusman            01234567 <-- The world famous Indent-o-Meter.

   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject or on a
   line by itself in the message (leave off the quotation marks):
                    "mail-request public-key"



Thu, 01 May 1997 23:01:34 GMT  
 Why is Perl5 getting invoked here?

: Can ANYONE out there state the exact rules that Perl uses for
: processing the '#!' line? ... i.e., under what exact circumstances is
: this done, what command-line flags affect this, etc. etc. ???

Sure, man perlrun and the source code.

Of the two, IMO, the source code is much more authoratative.

Regards,
<chaim>

--
Chaim Frenkel                                                   On contract at:

Nonlinear Knowledge, Inc.                              Bear Stearns & Co., Inc.



Sun, 04 May 1997 00:28:01 GMT  
 Why is Perl5 getting invoked here?

Quote:


> : Can ANYONE out there state the exact rules that Perl uses for
> : processing the '#!' line? ... i.e., under what exact circumstances is
> : this done, what command-line flags affect this, etc. etc. ???
> Sure, man perlrun and the source code.

Aha!  This has actually been documented in 'perlrun' ... thanks guys!
:):)

Quote:
> Of the two, IMO, the source code is much more authoratative.

Obviously. :) But as for using the source code as 'man' pages ...
well, you know what I feel about *that* kind of documentation ...  I
guess that would mean that all C programs written are
self-documenting. :)

Quote:
> --
> Chaim Frenkel                                                      On contract at:

> Nonlinear Knowledge, Inc.                         Bear Stearns & Co., Inc.

[ Note: Chaim, check your newsposter or mailer:  sometimes when
        I reply to you via email, the mail bounces back to me because
        your 'From:' line (or possibly 'Sender:' line ???) doesn't
        contain a valid return address for you.  My mailer works
        fine with 99% of the other people I reply to.

        How are you, by the way? :):)  ]

--
Lloyd Zusman            01234567 <-- The world famous Indent-o-Meter.

   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject or on a
   line by itself in the message (leave off the quotation marks):
                    "mail-request public-key"



Sun, 04 May 1997 20:48:21 GMT  
 Why is Perl5 getting invoked here?
: Ahhhhhhhhhh! <sigh of relief and joy>
:
: I *finally* got the answer I was looking for.  Thank you *very* much
: for this extremely useful information.  I assume that this excellent
: description of Perl's handling of '#!' is now, even as I post this
: reply, being feverishly inserted into the FAQ or into Perl's "pod"
: pages ...  :):)

There's already documentation for most of this in perlrun.  If you see
any omissions, please let Tom know.  Sorry nobody answered you last
month--I was busy *writing* the documentation at that point, and was
about 600 articles behind in comp.lang.perl.

I got caught up on that, but I still have about 400 message in my
mailbox from the time of VHLL that I have yet to read.  At some point
I might even start *fixing* bugs.  Things have been hectic around here.

Larry



Tue, 06 May 1997 05:26:33 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Why am I getting an error with @_ ?

2. Why am I getting this regexp error?

3. Why am I getting an undefined subroutine error?

4. FAQ 4.1 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

5. FAQ 4.1 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

6. FAQ 4.1 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

7. FAQ 4.1 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

8. FAQ: Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

9. FAQ: Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

10. FAQ: Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

11. FAQ: Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

12. FAQ: Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?

 

 
Powered by phpBB® Forum Software