SPUG: Bug in shebang parsing?

Tim Maher tim at consultix-inc.com
Mon Jul 5 15:16:53 CDT 2004


I've either found a bug in Perl, or there's an undocumented
"feature" that I've suddenly run into for the first time.
Either way, /I don't like it/! 8-{ 

In short, a parsing rule (or bug) seems to be operating that says
after two (or more) spaces are seen on the shebang line, no
additional options are recognized! So when one tries to use -s
for switch processing, and that switch is preceded by two spaces,
the result is that the -switch=whatever argument
is /retained/ on the command line, rather than used to set a
variable! When the -w option is in the ignored position, that
fails to enable warnings.

AFAIK, this is not documented behavior, and IMHO, it is not
/desirable/ behavior.

I've included sample programs and output below, and confirmed that
the same results are obtained with Perl versions 5.8.4 and 5.8.2.
Does anybody have an older Perl version handy to test? Does anybody
think this is not a bug? Any insights appreciated.


-Tim Maher
tim at teachmeperl.com

PROGRAMS:

The _sw ending on a test program means the -s option is first,
and the -w second, and so forth. The program invocation in each
case is "./scriptname -switch", which should set the $switch
variable in the script to 1. Note that there's nothing
switch-specific about this "two-space" bug -- that's just the
context in which I originally found it, and it demonstrates the
faulty behavior well, by (erroneously) leaving the -switch
argument in @ARGV, and triggering a "possible typo" warning
regarding $switch in that case.


2004-07-05 12:31                   one_space_sw                   Page 1

#! /usr/bin/perl -s -w
$switch == 1;
warn "Arguments are: @ARGV";


2004-07-05 12:31                   one_space_ws                   Page 1

#! /usr/bin/perl -w -s
$switch == 1;
warn "Arguments are: @ARGV";


2004-07-05 12:32                  two_spaces_sw                   Page 1

#! /usr/bin/perl -s  -w
$switch == 1;
warn "Arguments are: @ARGV";


2004-07-05 12:32                  two_spaces_ws                   Page 1

#! /usr/bin/perl -w  -s
$switch == 1;
warn "Arguments are: @ARGV";


OUTPUT:

RUNNING 'one_space_sw':
Useless use of numeric eq (==) in void context at ./one_space_sw line 3.
Arguments are:  at ./one_space_sw line 5.

(That's the correct result; warnings enabled, and switch-argument processed)

RUNNING 'one_space_ws':
Useless use of numeric eq (==) in void context at ./one_space_ws line 3.
Arguments are:  at ./one_space_ws line 5.

(That's the correct result; warnings enabled, and switch-argument processed)

RUNNING 'two_spaces_sw':
Arguments are:  at ./two_spaces_sw line 5.

(That's the WRONG result; warnings DISabled, and switch-argument processed)

RUNNING 'two_spaces_ws':
Useless use of numeric eq (==) in void context at ./two_spaces_ws line 3.
Name "main::switch" used only once: possible typo at ./two_spaces_ws line 3.
Use of uninitialized value in numeric eq (==) at ./two_spaces_ws line 3.
Arguments are: -switch at ./two_spaces_ws line 5.

(That's the WRONG result; warnings enabled, and switch-argument NOT processed)
 
==============================================================
| Tim Maher, Ph.D.                    tim(AT)TeachMePerl.com | 
| SPUG Leader Emeritus               spug(AT)TeachMePerl.com |
| Seattle Perl Users Group        http://www.SeattlePerl.com |
| SPUG Wiki Site               http://Spugwiki.Perlocity.org |
| Perl Certification Site      http://Perlcert.Perlocity.org |
==============================================================



More information about the spug-list mailing list