summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pod/perlsyn.pod2
-rw-r--r--toke.c27
2 files changed, 20 insertions, 9 deletions
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index f07bdfeabf..7b9590e4de 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -593,7 +593,7 @@ this, one can control Perl's idea of filenames and line numbers in
error or warning messages (especially for strings that are processed
with C<eval()>). The syntax for this mechanism is the same as for most
C preprocessors: it matches the regular expression
-C</^#\s*line\s+(\d+)\s*(?:\s"([^"]*)")?/> with C<$1> being the line
+C</^#\s*line\s+(\d+)\s*(?:\s"([^"]+)")?\s*$/> with C<$1> being the line
number for the next line, and C<$2> being the optional filename
(specified within quotes).
diff --git a/toke.c b/toke.c
index da4314d0ac..b6ffc2bdce 100644
--- a/toke.c
+++ b/toke.c
@@ -464,17 +464,22 @@ S_incline(pTHX_ char *s)
dTHR;
char *t;
char *n;
+ char *e;
char ch;
- int sawline = 0;
CopLINE_inc(PL_curcop);
if (*s++ != '#')
return;
while (*s == ' ' || *s == '\t') s++;
- if (strnEQ(s, "line ", 5)) {
- s += 5;
- sawline = 1;
- }
+ if (strnEQ(s, "line", 4))
+ s += 4;
+ else
+ return;
+ if (*s == ' ' || *s == '\t')
+ s++;
+ else
+ return;
+ while (*s == ' ' || *s == '\t') s++;
if (!isDIGIT(*s))
return;
n = s;
@@ -482,13 +487,19 @@ S_incline(pTHX_ char *s)
s++;
while (*s == ' ' || *s == '\t')
s++;
- if (*s == '"' && (t = strchr(s+1, '"')))
+ if (*s == '"' && (t = strchr(s+1, '"'))) {
s++;
+ e = t + 1;
+ }
else {
- if (!sawline)
- return; /* false alarm */
for (t = s; !isSPACE(*t); t++) ;
+ e = t;
}
+ while (*e == ' ' || *e == '\t' || *e == '\r' || *e == '\f')
+ e++;
+ if (*e != '\n' && *e != '\0')
+ return; /* false alarm */
+
ch = *t;
*t = '\0';
if (t - s > 0)