This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
do-file should not force a bareword
authorFather Chrysostomos <sprout@cpan.org>
Tue, 3 Jul 2012 01:11:23 +0000 (18:11 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 6 Jul 2012 01:14:03 +0000 (18:14 -0700)
A word following do is forced to be a bareword for do-sub’s sake.  But
if it is going to be interpreted as do-file after all, that does not
make sense.  ‘do subname;’ should call the sub and run the file whose
name it returns, instead of running the file named ‘subname’.

t/op/do.t
toke.c

index 5134fd4..177f1d2 100644 (file)
--- a/t/op/do.t
+++ b/t/op/do.t
@@ -302,4 +302,14 @@ SKIP: {
     ok($saved_errno,  "\$! set on io error");
 }
 
+# do subname should not be do "subname"
+{
+    my $called;
+    sub fungi { $called .= "fungible" }
+    $@ = "scrimptious scrobblings";
+    do fungi;
+    is $called, "fungible", "do-file does not force bareword";
+    isnt $@, "scrimptious scrobblings", "It was interpreted as do-file";
+}
+
 done_testing();
diff --git a/toke.c b/toke.c
index 1fa09d1..a51bf4d 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -7341,8 +7341,13 @@ Perl_yylex(pTHX)
            s = SKIPSPACE1(s);
            if (*s == '{')
                PRETERMBLOCK(DO);
-           if (*s != '\'')
-               s = force_word(s,WORD,TRUE,TRUE,FALSE);
+           if (*s != '\'') {
+               d = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, 1, &len);
+               if (len) {
+                   d = SKIPSPACE1(d);
+                   if (*d == '(') s = force_word(s,WORD,TRUE,TRUE,FALSE);
+               }
+           }
            if (orig_keyword == KEY_do) {
                orig_keyword = 0;
                pl_yylval.ival = 1;