From 25c09cbfff59747c663fe98ca4036df86a317a59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Salvador=20Fandi=C3=B1o?= Date: Fri, 17 Jun 2005 15:06:30 +0100 Subject: [PATCH] ternary operator cond ? foo : bar being parsed as ?...? Message-ID: <20050617130548.18776.qmail@lists.develooper.com> with wordings improvements suggested by Ronald J Kimball p4raw-id: //depot/perl@24920 --- pod/perldiag.pod | 10 ++++++++++ toke.c | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 94c1fd4..9e7e6d6 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -3449,6 +3449,16 @@ construct, not just the empty search pattern. Therefore code written in Perl 5.9.0 or later that uses the // as the I can be misparsed by pre-5.9.0 Perls as a non-terminated search pattern. +=item Search pattern not terminated or ternary operator parsed as search pattern + +(F) The lexer couldn't find the final delimiter of a C +construct. + +The question mark is also used as part of the ternary operator (as in +C) leading to some ambiguous constructions being wrongly +parsed. One way to disambiguate the parsing is to put parentheses around +the conditional expression, i.e. C<(foo) ? 0 : 1>. + =item %sseek() on unopened filehandle (W unopened) You tried to use the seek() or sysseek() function on a diff --git a/toke.c b/toke.c index ad50ec5..ac7599e 100644 --- a/toke.c +++ b/toke.c @@ -9261,8 +9261,12 @@ S_scan_pat(pTHX_ char *start, I32 type) PMOP *pm; char *s = scan_str(start,FALSE,FALSE); - if (!s) - Perl_croak(aTHX_ "Search pattern not terminated"); + if (!s) { + char *delimiter = skipspace(start); + Perl_croak(aTHX_ *delimiter == '?' + ? "Search pattern not terminated or ternary operator parsed as search pattern" + : "Search pattern not terminated" ); + } pm = (PMOP*)newPMOP(type, 0); if (PL_multi_open == '?') -- 1.8.3.1