This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Force _ to be always a bareword after filetest operators
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Tue, 18 Oct 2005 20:57:43 +0000 (20:57 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Tue, 18 Oct 2005 20:57:43 +0000 (20:57 +0000)
p4raw-id: //depot/perl@25799

t/op/filetest.t
toke.c

index 271c4f0..231242b 100755 (executable)
@@ -10,7 +10,7 @@ BEGIN {
 }
 
 use Config;
-plan(tests => 22);
+plan(tests => 24);
 
 ok( -d 'op' );
 ok( -f 'TEST' );
@@ -78,3 +78,10 @@ ok( ! -f -d 'op' );
 ok( -x -d -x 'op' );
 ok( (-s -f 'TEST' > 1), "-s returns real size" );
 ok( -f -s 'TEST' == 1 );
+
+# test that _ is a bareword after filetest operators
+
+-f 'TEST';
+ok( -f _ );
+sub _ { "this is not a file name" }
+ok( -f _ );
diff --git a/toke.c b/toke.c
index 4970df8..287aa94 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -4272,11 +4272,16 @@ Perl_yylex(pTHX)
 
                    /* If not a declared subroutine, it's an indirect object. */
                    /* (But it's an indir obj regardless for sort.) */
+                   /* Also, if "_" follows a filetest operator, it's a bareword */
 
-                   if ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
+                   if (
+                       ( !immediate_paren && (PL_last_lop_op == OP_SORT ||
                          ((!gv || !GvCVu(gv)) &&
                         (PL_last_lop_op != OP_MAPSTART &&
                         PL_last_lop_op != OP_GREPSTART))))
+                      || (PL_tokenbuf[0] == '_' && PL_tokenbuf[1] == '\0'
+                           && ((PL_opargs[PL_last_lop_op] & OA_CLASS_MASK) == OA_FILESTATOP))
+                      )
                    {
                        PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
                        goto bareword;