[PATCH] Re: SPUG:-s option doesn't always work!

Yitzchak Scott-Thoennes sthoenna at efn.org
Wed Jun 4 02:08:32 CDT 2003


On Tue, 3 Jun 2003 20:53:08 -0700, tim at consultix-inc.com wrote:
>I don't use the -s invocation option very often, but for certain
>categories of students, I think it works well.  So imagine my surprise
>when I learned today that -s on the shebang line seems to be ignored
>when the script is invoked as an argument to the perl command!
>Can anybody shed some light on this?

This is a bug.  See: http://rt.perl.org/rt2//Ticket/Display.html?id=7876
which fixed it in most cases in 5.8.0.  It appears to still be a problem
when -p or -n is specified on the shebang line but not the actual command
line.  This should fix it (full test still running):

--- perl/toke.c.orig	Fri May  9 15:39:28 2003
+++ perl/toke.c	Wed Jun  4 00:34:36 2003
@@ -2727,6 +2727,14 @@ Perl_yylex(pTHX)
 			    }
 			    d = moreswitches(d);
 			} while (d);
+			if (PL_doswitches && !switches_done) {
+			    int argc = PL_origargc;
+			    char **argv = PL_origargv;
+			    do {
+				argc--,argv++;
+			    } while (argc && argv[0][0] == '-' && argv[0][1]);
+			    init_argv_symbols(argc,argv);
+			}
 			if ((PERLDB_LINE && !oldpdb) ||
 			    ((PL_minus_n || PL_minus_p) && !(oldn || oldp)))
 			      /* if we have already added "LINE: while (<>) {",
@@ -2740,14 +2748,6 @@ Perl_yylex(pTHX)
 			    if (PERLDB_LINE)
 				(void)gv_fetchfile(PL_origfilename);
 			    goto retry;
-			}
-			if (PL_doswitches && !switches_done) {
-			    int argc = PL_origargc;
-			    char **argv = PL_origargv;
-			    do {
-				argc--,argv++;
-			    } while (argc && argv[0][0] == '-' && argv[0][1]);
-			    init_argv_symbols(argc,argv);
 			}
 		    }
 		}
--- perl/t/run/switches.t.orig	Thu Oct 17 14:45:52 2002
+++ perl/t/run/switches.t	Wed Jun  4 00:50:24 2003
@@ -126,12 +126,11 @@
 SKIP: {
     open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
     print $f <<'SWTEST';
-#!perl -s
-print $x
+#!perl -sn
+BEGIN { print $x; exit }
 SWTEST
     close $f or die "Could not close: $!";
     $r = runperl(
-	switches    => [ '-s' ],
 	progfile    => $filename,
 	args	    => [ '-x=foo' ],
     );
End of Patch.



More information about the spug-list mailing list