From: Rafael Garcia-Suarez Date: Tue, 18 Oct 2005 20:57:43 +0000 (+0000) Subject: Force _ to be always a bareword after filetest operators X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7294df96f6c174861cfdbe3e109c745792c2be60;p=p5sagit%2Fp5-mst-13.2.git Force _ to be always a bareword after filetest operators p4raw-id: //depot/perl@25799 --- diff --git a/t/op/filetest.t b/t/op/filetest.t index 271c4f0..231242b 100755 --- a/t/op/filetest.t +++ b/t/op/filetest.t @@ -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 --- 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;