Skip to content
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

Closed
p5pRT opened this issue Dec 24, 2012 · 28 comments
Closed

Warning if -F given but not -a #12669

p5pRT opened this issue Dec 24, 2012 · 28 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 24, 2012

Migrated from rt.perl.org#116190 (status was 'resolved')

Searchable as RT116190$

@p5pRT
Copy link
Author

p5pRT commented Dec 24, 2012

From @epa

Created by @epa

% perl -F​: -nE 'say $F[0]'

Here the user has forgotten the -a flag to split the string into @​F.
The -F option specifying the split delimiter has no effect if -a
is not also given. Perl should warn (or, preferably, fail with
an error) if command line usage gives -F but not -a.

Perl Info

Flags:
    category=core
    severity=low

This perlbug was built using Perl 5.14.3 in the Fedora build system.
It is being executed now by Perl 5.14.3 - Mon Nov 26 15:22:12 UTC 2012.

Site configuration information for perl 5.14.3:

Configured by Red Hat, Inc. at Mon Nov 26 15:22:12 UTC 2012.

Summary of my perl5 (revision 5 version 14 subversion 3) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-279.14.1.el6.x86_64, archname=x86_64-linux-thread-multi
    uname='linux buildvm-23.phx2.fedoraproject.org 2.6.32-279.14.1.el6.x86_64 #1 smp mon oct 15 13:44:51 edt 2012 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4  -m64 -mtune=generic -Dccdlflags=-Wl,--enable-new-dtags -DDEBUGGING=-g -Dversion=5.14.3 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.6.3 20120306 (Red Hat 4.6.3-2)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.14.90'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

Locally applied patches:
    


@INC for perl 5.14.3:
    /home/eda/lib/perl5//x86_64-linux-thread-multi
    /home/eda/lib/perl5/
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib64/perl5
    /usr/share/perl5
    .


Environment for perl 5.14.3:
    HOME=/home/eda
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=C
    LC_CTYPE=en_GB.UTF-8
    LC_MESSAGES=en_GB.UTF-8
    LC_MONETARY=en_GB.UTF-8
    LC_NUMERIC=en_GB.UTF-8
    LC_TIME=en_GB.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/eda/bin:/home/eda/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/sbin:/usr/sbin
    PERL5LIB=/home/eda/lib/perl5/
    PERL_BADLANG (unset)
    SHELL=/bin/bash

-- 
Ed Avis <eda@waniasset.com>



______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Dec 25, 2012

From @jkeenan

On Mon Dec 24 08​:19​:49 2012, eda@​waniasset.com wrote​:

This is a bug report for perl from eda@​waniasset.com,
generated with the help of perlbug 1.39 running under perl 5.14.3.

-----------------------------------------------------------------
[Please describe your issue here]

% perl -F​: -nE 'say $F[0]'

Here the user has forgotten the -a flag to split the string into @​F.
The -F option specifying the split delimiter has no effect if -a
is not also given. Perl should warn (or, preferably, fail with
an error) if command line usage gives -F but not -a.

Would it be possible for you to compose a test file for this --
something along the lines of t/run/switchF.t, switchF1.t, or switcha.t?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Dec 25, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jan 2, 2013

From @epa

Here is a test file for the behaviour suggested​:

#!perl
use 5.014;
use warnings;
use strict;
say 1;
my $cmd = "./perl -F​: -e 0";
my $got = `$cmd 2>&1`;
my $failure = $?;
my $result = "ok 1 - passing -F without -a gives error";
if ($failure and $got =~ /-F given without -a/) {
  say $result;
}
else {
  say "not $result";
}

--
Ed Avis <eda@​waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http​://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Jan 3, 2013

From @jkeenan

On Wed Jan 02 09​:15​:47 2013, eda@​waniasset.com wrote​:

Here is a test file for the behaviour suggested​:

#!perl
use 5.014;
use warnings;
use strict;
say 1;
my $cmd = "./perl -F​: -e 0";
my $got = `$cmd 2>&1`;
my $failure = $?;
my $result = "ok 1 - passing -F without -a gives error";
if ($failure and $got =~ /-F given without -a/) {
say $result;
}
else {
say "not $result";
}

Thanks for the patch. I had to rework it into a form suitable for
placement in t/run/, but it facilitated correction of the problem.

P5P​: please review the patch attached.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jan 3, 2013

From @jkeenan

From e701c5fa5e168ec52e39b9d38d4f4bfc8a5ecb58 Mon Sep 17 00​:00​:00 2001
From​: James E Keenan <jkeenan@​cpan.org>
Date​: Wed, 2 Jan 2013 19​:57​:52 -0500
Subject​: [PATCH] -F command-line option must be accompanied by -a option.

Responding to bug report by Ed Avis++. Enforce requirement
that -F be accompanied by -a. Create file to hold test for
this; update MANIFEST to list this. Add diagnostic for
fatal error.

For RT #116190.


MANIFEST | 1 +
perl.c | 20 +++++++++++---------
pod/perldiag.pod | 7 +++++++
t/run/switchF2.t | 14 ++++++++++++++
4 files changed, 33 insertions(+), 9 deletions(-)
create mode 100644 t/run/switchF2.t

Inline Patch
diff --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

@p5pRT
Copy link
Author

p5pRT commented Jan 3, 2013

From @tonycoz

On Wed, Jan 02, 2013 at 05​:03​:49PM -0800, James E Keenan via RT wrote​:

Thanks for the patch. I had to rework it into a form suitable for
placement in t/run/, but it facilitated correction of the problem.

P5P​: please review the patch attached.

As written​:

tony@​mars​:.../git/perl$ ./perl -Ilib -F​: -ae1
-F given without -a.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jan 3, 2013

From @jkeenan

On Wed Jan 02 19​:57​:34 2013, tonyc wrote​:

On Wed, Jan 02, 2013 at 05​:03​:49PM -0800, James E Keenan via RT wrote​:

Thanks for the patch. I had to rework it into a form suitable for
placement in t/run/, but it facilitated correction of the problem.

P5P​: please review the patch attached.

As written​:

tony@​mars​:.../git/perl$ ./perl -Ilib -F​: -ae1
-F given without -a.

Well, so much for that bright idea. :-)

Can anyone more familiar with perl.c suggest the correct approach?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jan 7, 2013

From @Tux

On Wed, 02 Jan 2013 17​:03​:49 -0800, "James E Keenan via RT"
<perlbug-followup@​perl.org> wrote​:

On Wed Jan 02 09​:15​:47 2013, eda@​waniasset.com wrote​:

Here is a test file for the behaviour suggested​:

#!perl
use 5.014;
use warnings;
use strict;
say 1;
my $cmd = "./perl -F​: -e 0";
my $got = `$cmd 2>&1`;
my $failure = $?;
my $result = "ok 1 - passing -F without -a gives error";
if ($failure and $got =~ /-F given without -a/) {
say $result;
}
else {
say "not $result";
}

Thanks for the patch. I had to rework it into a form suitable for
placement in t/run/, but it facilitated correction of the problem.

P5P​: please review the patch attached.

Is it too late to make -F *imply* -a ?

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.17 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @ap

* H.Merijn Brand <h.m.brand@​xs4all.nl> [2013-01-07 15​:50]​:

Is it too late to make -F *imply* -a ?

++

It’s spiteful for no good reason to tell the user that you know what
they are asking you to do, but you refuse to do it unless they ask for
it in just the right way. If you know what they want, just do it.

The code to do that is usually much simpler too, as is the case here
(though the test instead becomes slightly more complicated)​:

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @ap

0001-perl-116190-Make-the-F-switch-imply-a.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @epa

If -F implies -a, then -a should also imply -n.

--
Ed Avis <eda@​waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http​://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @ap

* Aristotle Pagaltzis <pagaltzis@​gmx.de> [2013-01-09 11​:29]​:

(though the test instead becomes slightly more complicated)​:

And I know not how Unix-ish a shell it requires to work correctly.
It’ll work on anything Bourne-ish. Whether CMD.EXE will like it –
that I have no idea of. (Nor whether any of the Win32 ports even
builds directly CMD.EXE… is there one?) VMS? Ask me not… Etc.

Someone who knows better than I, please review.

Regards,
--
Aristotle Pagaltzis // <http​://plasmasturm.org/>

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @Tux

On Wed, 9 Jan 2013 10​:31​:20 +0000, Ed Avis <eda@​waniasset.com> wrote​:

If -F implies -a, then -a should also imply -n.

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
fall into the same trap as the originally proposed patch

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.17 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @epa

If -F implies -a, then -a should also imply -n.

I'm not sure, I remember to have used -paF

-paF is equivalent to -pnaF, isn't it?

(ISTR that in the old days you had to give -pn, but in recent
perl versions -p now implies -n)

--
Ed Avis <eda@​waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http​://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Jan 9, 2013

From @ap

* H.Merijn Brand <h.m.brand@​xs4all.nl> [2013-01-09 11​:45]​:

if a implies -n, -p is negated after it has been set. Be sure not to
fall into the same trap as the originally proposed patch

That was my first thought but it turns out to be wrong. If you pass -p
then -p you get, no matter how many -n you also pass or where. So I see
no problem with Ed’s suggestion. I’ll cook another patch if no one beats
me to it.

@p5pRT
Copy link
Author

p5pRT commented Jan 11, 2013

From @khwilliamson

I agree that -F should imply -a

Any patch should include updates to perlrun

--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2013

From @rjbs

* Karl Williamson via RT <perlbug-followup@​perl.org> [2013-01-11T16​:43​:15]

I agree that -F should imply -a
Any patch should include updates to perlrun

Agreed. I wanted to have a look at whether I could see any weird way in which
-F could conceivably be of use, and saw nothing.

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
that​:

  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
'-F,' because it's the delimeter he or she most often wants and only activates
it when adding -a later, or the like. So far, I am unable to find myself much
persuaded by this thought.)

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jul 1, 2013

From @tonycoz

On Wed Jan 09 02​:50​:19 2013, aristotle wrote​:

* H.Merijn Brand <h.m.brand@​xs4all.nl> [2013-01-09 11​:45]​:

if a implies -n, -p is negated after it has been set. Be sure not to
fall into the same trap as the originally proposed patch

That was my first thought but it turns out to be wrong. If you pass -p
then -p you get, no matter how many -n you also pass or where. So I see
no problem with Ed’s suggestion. I’ll cook another patch if no one beats
me to it.

Have you had another chance to cook another patch?

For the test, you might want to consider fresh_perl_is() from test.pl to
test the output.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @tonycoz

On Sun Jun 30 22​:45​:24 2013, tonyc 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
test the output.

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
tests set -a, which made them block on stdin.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @tonycoz

0004-perl-116190-feed-an-empty-stdin-to-run_multiple_prog.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @tonycoz

0003-perl-116190-F-and-a-now-imply-n.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @tonycoz

0002-perl-116190-use-the-true-and-trusted-fresh_perl_is.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @ap

* Tony Cook via RT <perlbug-followup@​perl.org> [2013-07-16 07​:05]​:

Here's 3 changes in addition to aristotle's change​:

Thanks for taking this off my todo list. :-)

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @Tux

On Mon, 15 Jul 2013 22​:02​:31 -0700, "Tony Cook via RT"
<perlbug-followup@​perl.org> wrote​:

to allow -paF, wouldn't it be better to not imply -n if -p was already
passed?

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;
  if (PL_minus_p != 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;
  if (PL_minus_p != TRUE) PL_minus_n = TRUE;
s++;
return s;
case 'c'​:

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.19 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @ap

* H.Merijn Brand <h.m.brand@​xs4all.nl> [2013-07-16 09​:05]​:

to allow -paF, wouldn't it be better to not imply -n if -p was already
passed?

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'​:
  PL_minus_n = TRUE;
  s++;
  return s;
  case 'p'​:
  PL_minus_p = TRUE;
  s++;
  return s;

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
  LINE​: while (defined($_ = <ARGV>)) {
  '???';
  }
  -e syntax OK

And this is what happens when both are set​:

  $ perl -MO=Deparse -p -n -n -n -n -n -n -n -n -n -n -e1
  LINE​: while (defined($_ = <ARGV>)) {
  '???';
  }
  continue {
  die "-p destination​: $!\n" unless print $_;
  }
  -e syntax OK

In other words, when both are set, you get PL_minus_p behaviour regardless of
whether PL_minus_n is set.

You seem to have thought otherwise, but this is how it works.

So the guard clauses you suggest are no-ops.

Regards,
--
Aristotle Pagaltzis // <http​://plasmasturm.org/>

@p5pRT
Copy link
Author

p5pRT commented Jul 23, 2013

From @tonycoz

On Mon Jul 15 22​:02​:31 2013, tonyc wrote​:

On Sun Jun 30 22​:45​:24 2013, tonyc 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
test the output.

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
tests set -a, which made them block on stdin.

All four applied as merge commit 1d5bb6b.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 23, 2013

@tonycoz - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant