develooper Front page | perl.perl5.porters | Postings from November 2008

Re: [perl #32979] perlrun #!/bin/sh incantation n.g. 4 linux

Thread Previous
From:
Graham Barr
Date:
November 27, 2008 14:46
Subject:
Re: [perl #32979] perlrun #!/bin/sh incantation n.g. 4 linux
Message ID:
605D1808-C387-478E-86BF-1CB979AEF3D0@pobox.com
On Nov 26, 2008, at 11:52 PM, Steve Peters via RT wrote:
>> The following patch to perlrun.pod applies the change suggested  
>> above.
>>
>> --- perlrun.pod.orig    Tue Dec 21 11:32:41 2004
>> +++ perlrun.pod Tue Dec 21 11:34:34 2004
>> @@ -79,9 +79,10 @@
>> 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;
>> +    #!/bin/sh
>> +    #! -*-perl-*-
>> +    eval 'exec perl -x -wS $0 ${1+"$@"}'
>> +        if 0;

It should be pointed out that a caveat of using -x is that line  
numbers as reported by perl will no longer reflect the line counting  
from the first line in the file, but instead counting from the #! -*- 
perl-*-. This can confuse people, eg

#!/bin/sh
#! -*-perl-*-
eval 'exec perl -x -wS $0 ${1+"$@"}'
     if 0;
die "x";

gives:
x at /tmp/foo line 4.

But the die is on line 5. This offset will grow if more comments, or  
shell code, are placed before the #!perl line
This can be manually resolved with a #line directive

#!/bin/sh
#! -*-perl-*-
#line 4
eval 'exec perl -x -wS $0 ${1+"$@"}'
     if 0;
die "x";

gives:
x at /tmp/foo line 6.

Graham.


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About