diff options
author | Tomasz Konojacki <me@xenu.pl> | 2022-02-16 06:29:25 +0100 |
---|---|---|
committer | xenu <me@xenu.pl> | 2022-02-19 20:22:34 +0100 |
commit | 9cb26ed2ae572b61849be5ef0d9e2fc19c8e49a8 (patch) | |
tree | 6b19cd068088cde39d6c01f53358d91ffa16a27b | |
parent | c58eeaf60f6c5d06d95da1941e0b0b16e3025f0d (diff) | |
download | perl-9cb26ed2ae572b61849be5ef0d9e2fc19c8e49a8.tar.gz |
implement a new command-line flag, -g
It's a simpler alias for -0777. It was proposed in RFC-0011:
https://github.com/Perl/RFCs/blob/master/rfcs/rfc0011.md
-rw-r--r-- | perl.c | 6 | ||||
-rw-r--r-- | pod/perldelta.pod | 6 | ||||
-rw-r--r-- | pod/perlrun.pod | 17 | ||||
-rw-r--r-- | t/run/switches.t | 10 |
4 files changed, 36 insertions, 3 deletions
@@ -2098,6 +2098,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) case 'c': case 'd': case 'D': + case 'g': case '?': case 'h': case 'i': @@ -3553,6 +3554,11 @@ Perl_moreswitches(pTHX_ const char *s) return s; NOT_REACHED; /* NOTREACHED */ } + case 'g': + SvREFCNT_dec(PL_rs); + PL_rs = &PL_sv_undef; + sv_setsv(get_sv("/", GV_ADD), PL_rs); + return ++s; case '?': /* FALLTHROUGH */ diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 311d06bf6e..e2a71093d3 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -64,6 +64,12 @@ C<use v5.36>. For more detail see L<perlop/Class Instance Operator>. +=head2 -g command-line flag + +A new command-line flag, -g, is available. It is a simpler alias for -0777. + +For more information, see L<perlrun/-g>. + =head1 Security XXX Any security-related notices go here. In particular, any security diff --git a/pod/perlrun.pod b/pod/perlrun.pod index 0683ef128d..0c3616a799 100644 --- a/pod/perlrun.pod +++ b/pod/perlrun.pod @@ -4,7 +4,7 @@ perlrun - how to execute the Perl interpreter =head1 SYNOPSIS -B<perl> S<[ B<-sTtuUWX> ]> +B<perl> S<[ B<-gsTtuUWX> ]> S<[ B<-h?v> ] [ B<-V>[:I<configvar>] ]> S<[ B<-cw> ] [ B<-d>[B<t>][:I<debugger>] ] [ B<-D>[I<number/list>] ]> S<[ B<-pna> ] [ B<-F>I<pattern> ] [ B<-l>[I<octal>] ] [ B<-0>[I<octal/hexadecimal>] ]> @@ -241,8 +241,10 @@ terminated by the null character, you can say this: find . -name '*.orig' -print0 | perl -n0e unlink The special value 00 will cause Perl to slurp files in paragraph mode. + Any value 0400 or above will cause Perl to slurp files whole, but by convention -the value 0777 is the one normally used for this purpose. +the value 0777 is the one normally used for this purpose. The L</-g> flag +is a simpler alias for it. You can also specify the separator character using hexadecimal notation: B<-0xI<HHH...>>, where the C<I<H>> are valid hexadecimal digits. Unlike @@ -511,6 +513,17 @@ quotes. You can't use literal whitespace or NUL characters in the pattern. B<-F> implicitly sets both L</-a> and L</-n>. +=item B<-g> +X<-g> + +undefines the input record separator (C<L<$E<sol>|perlvar/$E<sol>>>) and thus +enables the slurp mode. In other words, it causes Perl to read whole +files at once, instead of line by line. + +This flag is a simpler alias for L<-0777|/-0[octalE<sol>hexadecimal]>. + +Mnemonics: gobble, grab, gulp. + =item B<-h> X<-h> diff --git a/t/run/switches.t b/t/run/switches.t index 00df1f37e2..44b35a7418 100644 --- a/t/run/switches.t +++ b/t/run/switches.t @@ -73,6 +73,14 @@ $r = runperl( ); is( $r, "(\066)[\066]", '$/ set at compile-time' ); +# Tests for -g + +$r = runperl( + switches => [ '-g' ], + prog => 'BEGIN { printf q<(%d)>, defined($/) } printf q<[%d]>, defined($/)', +); +is( $r, "(0)[0]", '-g undefines $/ at compile-time' ); + # Tests for -c my $filename = tempfile(); @@ -324,7 +332,7 @@ is runperl(stderr => 1, prog => '#!perl -M'), # Tests for switches which do not exist -foreach my $switch (split //, "ABbGgHJjKkLNOoPQqRrYyZz123456789_") +foreach my $switch (split //, "ABbGHJjKkLNOoPQqRrYyZz123456789_") { local $TODO = ''; # these ones should work on VMS |