New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning if -F given but not -a #12669
Comments
From @epaCreated by @epa% perl -F: -nE 'say $F[0]' Here the user has forgotten the -a flag to split the string into @F. Perl Info
|
From @jkeenanOn Mon Dec 24 08:19:49 2012, eda@waniasset.com wrote:
Would it be possible for you to compose a test file for this -- Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @epaHere is a test file for the behaviour suggested: #!perl -- ______________________________________________________________________ |
From @jkeenanOn Wed Jan 02 09:15:47 2013, eda@waniasset.com wrote:
Thanks for the patch. I had to rework it into a form suitable for P5P: please review the patch attached. Thank you very much. |
From @jkeenanFrom e701c5fa5e168ec52e39b9d38d4f4bfc8a5ecb58 Mon Sep 17 00:00:00 2001 Responding to bug report by Ed Avis++. Enforce requirement For RT #116190. MANIFEST | 1 + Inline Patchdiff --git a/MANIFEST b/MANIFEST
index ffb79ac..c5d22db 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -5522,6 +5522,7 @@ t/run/switchd-78586.t See whether bug 78586 is fixed
t/run/switchd.t Test the -d switch
t/run/switches.t Tests for the other switches (-0, -l, -c, -s, -M, -m, -V, -v, -h, -z, -i)
t/run/switchF1.t Pathological tests for the -F switch
+t/run/switchF2.t Test the -F -a switch combination
t/run/switchF.t Test the -F switch
t/run/switchI.t Test the -I switch
t/run/switchn.t Test the -n switch
diff --git a/perl.c b/perl.c
index 0cfb73c..f079b77 100644
--- a/perl.c
+++ b/perl.c
@@ -3121,16 +3121,18 @@ Perl_moreswitches(pTHX_ const char *s)
if (PL_unicode & PERL_UNICODE_UTF8CACHEASSERT_FLAG)
PL_utf8cache = -1;
return s;
- case 'F':
- PL_minus_F = TRUE;
- PL_splitstr = ++s;
- while (*s && !isSPACE(*s)) ++s;
- PL_splitstr = savepvn(PL_splitstr, s - PL_splitstr);
- return s;
case 'a':
- PL_minus_a = TRUE;
- s++;
- return s;
+ PL_minus_a = TRUE;
+ s++;
+ return s;
+ case 'F':
+ if (!PL_minus_a)
+ Perl_croak(aTHX_ "-F given without -a");
+ PL_minus_F = TRUE;
+ PL_splitstr = ++s;
+ while (*s && !isSPACE(*s)) ++s;
+ PL_splitstr = savepvn(PL_splitstr, s - PL_splitstr);
+ return s;
case 'c':
PL_minus_c = TRUE;
s++;
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 600436f..bcef569 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -1882,6 +1882,13 @@ e.g. bless($ref, $p || 'MyPackage');
(A) You've accidentally run your script through B<csh> instead of Perl.
Check the #! line, or manually feed your script into Perl yourself.
+=item -F given without -a
+
+(F) The C<-F> option was passed on the command line but it was not accompanied
+by a C<-a> option. The C<-F> option specifies the pattern to split on if and
+only if C<-a>, which turns on the autosplit mode, is also in effect. See
+L<perlrun> for more details.
+
=item %s failed--call queue aborted
(F) An untrapped exception was raised while executing a UNITCHECK,
diff --git a/t/run/switchF2.t b/t/run/switchF2.t
new file mode 100644
index 0000000..aadc205
--- /dev/null
+++ b/t/run/switchF2.t
@@ -0,0 +1,14 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require './test.pl';
+}
+plan(tests => 1);
+
+my $cmd = "./perl -F: -e 0";
+my $got = `$cmd 2>&1` || '';
+my $failure = $?;
+ok( ($failure and $got =~ /-F given without -a/),
+ "passing -F without -a gives error" );
--
1.6.3.2 |
From @tonycozOn Wed, Jan 02, 2013 at 05:03:49PM -0800, James E Keenan via RT wrote:
As written: tony@mars:.../git/perl$ ./perl -Ilib -F: -ae1 Tony |
From @jkeenanOn Wed Jan 02 19:57:34 2013, tonyc wrote:
Well, so much for that bright idea. :-) Can anyone more familiar with perl.c suggest the correct approach? Thank you very much. |
From @TuxOn Wed, 02 Jan 2013 17:03:49 -0800, "James E Keenan via RT"
Is it too late to make -F *imply* -a ? -- |
From @ap* H.Merijn Brand <h.m.brand@xs4all.nl> [2013-01-07 15:50]:
++ It’s spiteful for no good reason to tell the user that you know what The code to do that is usually much simpler too, as is the case here |
From @ap0001-perl-116190-Make-the-F-switch-imply-a.patchFrom 092e84e616d9cb3cd5a6f8a591bf010ede6f0b30 Mon Sep 17 00:00:00 2001
Message-Id: <092e84e616d9cb3cd5a6f8a591bf010ede6f0b30.1357727233.git.pagaltzis@gmx.de>
From: Aristotle Pagaltzis <pagaltzis@gmx.de>
Date: Wed, 9 Jan 2013 11:26:56 +0100
Subject: [PATCH] [perl #116190] Make the -F switch imply -a
---
MANIFEST | 1 +
perl.c | 1 +
t/run/switchF2.t | 15 +++++++++++++++
3 files changed, 17 insertions(+), 0 deletions(-)
create mode 100644 t/run/switchF2.t
diff --git a/MANIFEST b/MANIFEST
index 2dd04ec..009c0ef 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -5465,6 +5465,7 @@ t/run/switchd-78586.t See whether bug 78586 is fixed
t/run/switchd.t Test the -d switch
t/run/switches.t Tests for the other switches (-0, -l, -c, -s, -M, -m, -V, -v, -h, -z, -i)
t/run/switchF1.t Pathological tests for the -F switch
+t/run/switchF2.t Test the -F -a switch combination
t/run/switchF.t Test the -F switch
t/run/switchI.t Test the -I switch
t/run/switchn.t Test the -n switch
diff --git a/perl.c b/perl.c
index 65b0a1c..6e7f88d 100644
--- a/perl.c
+++ b/perl.c
@@ -3083,6 +3083,7 @@ Perl_moreswitches(pTHX_ const char *s)
PL_utf8cache = -1;
return s;
case 'F':
+ PL_minus_a = TRUE;
PL_minus_F = TRUE;
PL_splitstr = ++s;
while (*s && !isSPACE(*s)) ++s;
diff --git a/t/run/switchF2.t b/t/run/switchF2.t
new file mode 100644
index 0000000..51136d2
--- /dev/null
+++ b/t/run/switchF2.t
@@ -0,0 +1,15 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require './test.pl';
+}
+plan(tests => 1);
+
+my $cmd = "echo 1 | ./perl -n -F: -e print+\\\@F";
+my $got = `$cmd` || '';
+my $ok = 0 == $?;
+chomp $got;
+ok( ($ok and $got eq 1),
+ "passing -F implies -a" );
--
1.7.4.4
|
From @epaIf -F implies -a, then -a should also imply -n. -- ______________________________________________________________________ |
From @ap* Aristotle Pagaltzis <pagaltzis@gmx.de> [2013-01-09 11:29]:
And I know not how Unix-ish a shell it requires to work correctly. Someone who knows better than I, please review. Regards, |
From @TuxOn Wed, 9 Jan 2013 10:31:20 +0000, Ed Avis <eda@waniasset.com> wrote:
I'm not sure, I remember to have used -paF if a implies -n, -p is negated after it has been set. Be sure not to -- |
From @epa
-paF is equivalent to -pnaF, isn't it? (ISTR that in the old days you had to give -pn, but in recent -- ______________________________________________________________________ |
From @ap* H.Merijn Brand <h.m.brand@xs4all.nl> [2013-01-09 11:45]:
That was my first thought but it turns out to be wrong. If you pass -p |
From @khwilliamsonI agree that -F should imply -a Any patch should include updates to perlrun -- |
From @rjbs* Karl Williamson via RT <perlbug-followup@perl.org> [2013-01-11T16:43:15]
Agreed. I wanted to have a look at whether I could see any weird way in which Also, is there a reason that -a should not imply -n? As near as I can tell, using -n does not preclude -p being added, which means perl -an -F: -E 'say $F[4]' could become: perl -F: -E 'say $F[4]' I don't see a reason. (There's some chance that someone has set PERL5OPT to -- |
From @tonycozOn Wed Jan 09 02:50:19 2013, aristotle wrote:
Have you had another chance to cook another patch? For the test, you might want to consider fresh_perl_is() from test.pl to Tony |
From @tonycozOn Sun Jun 30 22:45:24 2013, tonyc wrote:
Here's 3 changes in addition to aristotle's change: 0002 - change to use fresh_perl_is() 0003 - make -a and -F also imply -n 0004 - alter run_multiple_progs() to supply an empty stdin, two warnings Tony |
From @tonycoz0004-perl-116190-feed-an-empty-stdin-to-run_multiple_prog.patchFrom fc640d8b9d9baaed0ce6de80f25d1ab2c1148452 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Tue, 16 Jul 2013 14:57:20 +1000
Subject: [PATCH 4/4] [perl #116190] feed an empty stdin to
run_multiple_progs() programs
Two tests for -a were attempting to read stdin and blocking with the -a
implies -n change.
---
t/test.pl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/t/test.pl b/t/test.pl
index e141b91..9f8ed07 100644
--- a/t/test.pl
+++ b/t/test.pl
@@ -1059,7 +1059,8 @@ sub run_multiple_progs {
print $fh "\n#line 1\n"; # So the line numbers don't get messed up.
print $fh $prog,"\n";
close $fh or die "Cannot close $tmpfile: $!";
- my $results = runperl( stderr => 1, progfile => $tmpfile, $up
+ my $results = runperl( stderr => 1, progfile => $tmpfile,
+ stdin => '', $up
? (switches => ["-I$up/lib", $switch], nolib => 1)
: (switches => [$switch])
);
--
1.7.10.4
|
From @tonycoz0003-perl-116190-F-and-a-now-imply-n.patchFrom 9b2f2102fc3fda3a3013588dae18a938397911d7 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Tue, 16 Jul 2013 12:11:55 +1000
Subject: [PATCH 3/4] [perl #116190] -F and -a now imply -n
---
perl.c | 2 ++
pod/perlrun.pod | 10 +++++++---
t/run/switchF2.t | 12 +++++++++++-
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/perl.c b/perl.c
index 41a62b7..5458c1d 100644
--- a/perl.c
+++ b/perl.c
@@ -3215,12 +3215,14 @@ Perl_moreswitches(pTHX_ const char *s)
case 'F':
PL_minus_a = TRUE;
PL_minus_F = TRUE;
+ PL_minus_n = TRUE;
PL_splitstr = ++s;
while (*s && !isSPACE(*s)) ++s;
PL_splitstr = savepvn(PL_splitstr, s - PL_splitstr);
return s;
case 'a':
PL_minus_a = TRUE;
+ PL_minus_n = TRUE;
s++;
return s;
case 'c':
diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index 05dea4e..dbaa12c 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -265,6 +265,8 @@ is equivalent to
An alternate delimiter may be specified using B<-F>.
+B<-a> implicitly sets B<-n>.
+
=item B<-C [I<number/list>]>
X<-C>
@@ -487,9 +489,11 @@ perl, you can check the value of C<$Config{usesitecustomize}>.
=item B<-F>I<pattern>
X<-F>
-specifies the pattern to split on if B<-a> is also in effect. The
-pattern may be surrounded by C<//>, C<"">, or C<''>, otherwise it will be
-put in single quotes. You can't use literal whitespace in the pattern.
+specifies the pattern to split on for B<-a>. The pattern may be
+surrounded by C<//>, C<"">, or C<''>, otherwise it will be put in single
+quotes. You can't use literal whitespace in the pattern.
+
+B<-F> implicitly sets both B<-a> and B<-n>.
=item B<-h>
X<-h>
diff --git a/t/run/switchF2.t b/t/run/switchF2.t
index 5e99e1e..a411711 100644
--- a/t/run/switchF2.t
+++ b/t/run/switchF2.t
@@ -5,7 +5,7 @@ BEGIN {
@INC = '../lib';
require './test.pl';
}
-plan(tests => 1);
+plan(tests => 3);
{ # perl #116190
fresh_perl_is('print qq!@F!', '1 2',
@@ -13,4 +13,14 @@ plan(tests => 1);
stdin => "1:2",
switches => [ '-n', '-F:' ],
}, "passing -F implies -a");
+ fresh_perl_is('print qq!@F!', '1 2',
+ {
+ stdin => "1:2",
+ switches => [ '-F:' ],
+ }, "passing -F implies -an");
+ fresh_perl_is('print join q!,!, @F', '1,2',
+ {
+ stdin => "1 2",
+ switches => [ '-a' ],
+ }, "passing -a implies -n");
}
--
1.7.10.4
|
From @tonycoz0002-perl-116190-use-the-true-and-trusted-fresh_perl_is.patchFrom 2c8f357c7607c454281c069e555784dde27cd71a Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Tue, 16 Jul 2013 12:00:41 +1000
Subject: [PATCH 2/4] [perl #116190] use the true and trusted fresh_perl_is()
instead of re-inventing it yet again
---
t/run/switchF2.t | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/t/run/switchF2.t b/t/run/switchF2.t
index 51136d2..5e99e1e 100644
--- a/t/run/switchF2.t
+++ b/t/run/switchF2.t
@@ -7,9 +7,10 @@ BEGIN {
}
plan(tests => 1);
-my $cmd = "echo 1 | ./perl -n -F: -e print+\\\@F";
-my $got = `$cmd` || '';
-my $ok = 0 == $?;
-chomp $got;
-ok( ($ok and $got eq 1),
- "passing -F implies -a" );
+{ # perl #116190
+ fresh_perl_is('print qq!@F!', '1 2',
+ {
+ stdin => "1:2",
+ switches => [ '-n', '-F:' ],
+ }, "passing -F implies -a");
+}
--
1.7.10.4
|
From @ap* Tony Cook via RT <perlbug-followup@perl.org> [2013-07-16 07:05]:
Thanks for taking this off my todo list. :-) |
From @TuxOn Mon, 15 Jul 2013 22:02:31 -0700, "Tony Cook via RT" to allow -paF, wouldn't it be better to not imply -n if -p was already
-- |
From @ap* H.Merijn Brand <h.m.brand@xs4all.nl> [2013-07-16 09:05]:
Haven’t we gone over this before? No. It would make zero difference. This is the code for parsing the -n and -p switches: case 'n': So if you pass both -n and -p, both flags get set. This is what happens when PL_minus_n is set: $ perl -MO=Deparse -n -e1 And this is what happens when both are set: $ perl -MO=Deparse -p -n -n -n -n -n -n -n -n -n -n -e1 In other words, when both are set, you get PL_minus_p behaviour regardless of You seem to have thought otherwise, but this is how it works. So the guard clauses you suggest are no-ops. Regards, |
From @tonycozOn Mon Jul 15 22:02:31 2013, tonyc wrote:
All four applied as merge commit 1d5bb6b. Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#116190 (status was 'resolved')
Searchable as RT116190$
The text was updated successfully, but these errors were encountered: