diff options
author | Rafael Garcia-Suarez <rgs@consttype.org> | 2014-07-24 17:43:29 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgs@consttype.org> | 2014-09-30 08:17:50 +0200 |
commit | 157fb5a14d10ed16ffc6ebfc43d2637a016fdfce (patch) | |
tree | b2410287e269d41f3295678586e62ce4fa459188 /toke.c | |
parent | f276fdad8f6660f36944c895587a7748585e4969 (diff) | |
download | perl-157fb5a14d10ed16ffc6ebfc43d2637a016fdfce.tar.gz |
Introduce the double-diamond operator <<>>
This operator works like <> or <ARGV>, as it reads the list of file
names to open from the command-line arguments. However, it disables
the magic-open feature (that forks to execute piped commands) :
$ bleadperl -e 'while(<>){print}' 'echo foo |'
foo
$ bleadperl -e 'while(<<>>){print}' 'echo foo |'
Can't open echo foo |: No such file or directory at -e line 1.
Diffstat (limited to 'toke.c')
-rw-r--r-- | toke.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -5796,7 +5796,7 @@ Perl_yylex(pTHX) if (PL_expect != XOPERATOR) { if (s[1] != '<' && !strchr(s,'>')) check_uni(); - if (s[1] == '<') + if (s[1] == '<' && s[2] != '>') s = scan_heredoc(s); else s = scan_inputsymbol(s); @@ -9279,6 +9279,7 @@ S_scan_heredoc(pTHX_ char *s) This code handles: <> read from ARGV + <<>> read from ARGV without magic open <FH> read from filehandle <pkg::FH> read from package qualified filehandle <pkg'FH> read from package qualified filehandle @@ -9293,6 +9294,7 @@ S_scan_inputsymbol(pTHX_ char *start) char *s = start; /* current position in buffer */ char *end; I32 len; + bool nomagicopen = FALSE; char *d = PL_tokenbuf; /* start of temp holding space */ const char * const e = PL_tokenbuf + sizeof PL_tokenbuf; /* end of temp holding space */ @@ -9301,7 +9303,14 @@ S_scan_inputsymbol(pTHX_ char *start) end = strchr(s, '\n'); if (!end) end = PL_bufend; - s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ + if (s[1] == '<' && s[2] == '>' && s[3] == '>') { + nomagicopen = TRUE; + *d = '\0'; + len = 0; + s += 3; + } + else + s = delimcpy(d, e, s + 1, end, '>', &len); /* extract until > */ /* die if we didn't have space for the contents of the <>, or if it didn't end, or if we see a newline @@ -9411,7 +9420,7 @@ intro_sym: op_append_elem(OP_LIST, newGVOP(OP_GV, 0, gv), newCVREF(0, newGVOP(OP_GV, 0, gv_readline)))) - : (OP*)newUNOP(OP_READLINE, 0, newGVOP(OP_GV, 0, gv)); + : (OP*)newUNOP(OP_READLINE, nomagicopen ? OPf_SPECIAL : 0, newGVOP(OP_GV, 0, gv)); pl_yylval.ival = OP_NULL; } } |