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