in reply to A little Christmas switch wish..
It should doesn't break any of the regression tests. It may break binary compatibility. Use at your own risk. Try this demonstration:LINE: while (<DATA>) { }
Merry Christmas!#!/usr/bin/perl -wNp use strict; $_ = reverse $_; __DATA__ citamorhc si !sdrawkcab
Update: (Wed Dec 12 18:20:00 UTC 2001) I missed a couple of spots in perl.c. They've been added to the patch above. They're the first two chunks in that file, and now it works from the command line.--- ~intrpvar.h Tue Dec 11 13:20:28 2001 +++ intrpvar.h Tue Dec 11 13:20:41 2001 @@ -27,6 +27,7 @@ PERLVARI(Isplitstr, char *, " ") PERLVAR(Ipreprocess, bool) PERLVAR(Iminus_n, bool) +PERLVAR(Iminus_N, bool) PERLVAR(Iminus_p, bool) PERLVAR(Iminus_l, bool) PERLVAR(Iminus_a, bool) --- ~perl.c Tue Dec 11 13:13:15 2001 +++ perl.c Wed Dec 12 11:16:14 2001 @@ -1087,6 +1087,7 @@ case 'M': case 'm': case 'n': + case 'N': case 'p': case 's': case 'u': @@ -2135,6 +2136,7 @@ "-l[octal] enable line ending processing, specifies line termin +ator", "-[mM][-]module execute `use/no module...' before executing program" +, "-n assume 'while (<>) { ... }' loop around program", +"-N assume 'while (<DATA>) { ... }' loop around program" +, "-p assume loop like -n but print line also, like sed", "-P run program through C preprocessor before compilatio +n", "-s enable rudimentary parsing for switches after progra +mfile", @@ -2361,6 +2363,11 @@ Perl_croak(aTHX_ "No space allowed after -%c", *(s-1)); return s; case 'n': + PL_minus_n = TRUE; + s++; + return s; + case 'N': + PL_minus_N = TRUE; PL_minus_n = TRUE; s++; return s; --- ~sv.c Tue Dec 11 13:19:16 2001 +++ sv.c Tue Dec 11 13:19:33 2001 @@ -9825,6 +9825,7 @@ PL_splitstr = proto_perl->Isplitstr; PL_preprocess = proto_perl->Ipreprocess; PL_minus_n = proto_perl->Iminus_n; + PL_minus_N = proto_perl->Iminus_N; PL_minus_p = proto_perl->Iminus_p; PL_minus_l = proto_perl->Iminus_l; PL_minus_a = proto_perl->Iminus_a; --- ~toke.c Tue Dec 11 13:14:33 2001 +++ toke.c Tue Dec 11 13:32:02 2001 @@ -2435,7 +2435,11 @@ PL_preambleav = NULL; } if (PL_minus_n || PL_minus_p) { - sv_catpv(PL_linestr, "LINE: while (<>) {"); + if (PL_minus_N) { + sv_catpv(PL_linestr, "LINE: while (<DATA>) {"); + } else { + sv_catpv(PL_linestr, "LINE: while (<>) {"); + } if (PL_minus_l) sv_catpv(PL_linestr,"chomp;"); if (PL_minus_a) {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: A little Christmas switch wish..
by demerphq (Chancellor) on Dec 12, 2001 at 17:59 UTC |