allow C<print v10>, $h{v13.10} etc.
Gurusamy Sarathy [Tue, 22 Feb 2000 07:35:47 +0000 (07:35 +0000)]
p4raw-id: //depot/perl@5191

t/op/ver.t
toke.c

index 93ad1f3..206b1d0 100755 (executable)
@@ -5,7 +5,7 @@ BEGIN {
     unshift @INC, "../lib";
 }
 
-print "1..14\n";
+print "1..18\n";
 
 my $test = 1;
 
@@ -13,6 +13,25 @@ use v5.5.640;
 require v5.5.640;
 print "ok $test\n";  ++$test;
 
+# printing characters should work
+print v111;
+print v107.32;
+print "$test\n"; ++$test;
+
+# hash keys too
+$h{v111.107} = "ok";
+print "$h{ok} $test\n"; ++$test;
+
+# poetry optimization should also
+sub v77 { "ok" }
+$x = v77;
+print "$x $test\n"; ++$test;
+
+# but not when dots are involved
+$x = v77.78.79;
+print "not " unless $x eq "MNO";
+print "ok $test\n";  ++$test;
+
 print "not " unless v1.20.300.4000 eq "\x{1}\x{14}\x{12c}\x{fa0}";
 print "ok $test\n";  ++$test;
 
diff --git a/toke.c b/toke.c
index 6107d77..727fc01 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3467,7 +3467,7 @@ Perl_yylex(pTHX)
        OPERATOR(REFGEN);
 
     case 'v':
-       if (isDIGIT(s[1]) && PL_expect == XTERM) {
+       if (isDIGIT(s[1]) && PL_expect != XOPERATOR) {
            char *start = s;
            start++;
            start++;
@@ -3477,6 +3477,18 @@ Perl_yylex(pTHX)
                s = scan_num(s);
                TERM(THING);
            }
+           /* avoid v123abc() or $h{v1}, allow C<print v10;> */
+           else if (!isALPHA(*start) && (PL_expect == XTERM || PL_expect == XREF)) {
+               char c = *start;
+               GV *gv;
+               *start = '\0';
+               gv = gv_fetchpv(s, FALSE, SVt_PVCV);
+               *start = c;
+               if (!gv) {
+                   s = scan_num(s);
+                   TERM(THING);
+               }
+           }
        }
        goto keylookup;
     case 'x':
@@ -6904,7 +6916,7 @@ Perl_scan_num(pTHX_ char *start)
            pos++;
            while (isDIGIT(*pos))
                pos++;
-           if (*pos == '.' && isDIGIT(pos[1])) {
+           if (!isALPHA(*pos)) {
                UV rev;
                U8 tmpbuf[UTF8_MAXLEN];
                U8 *tmpend;
@@ -6914,32 +6926,22 @@ Perl_scan_num(pTHX_ char *start)
                sv = NEWSV(92,5);
                sv_setpvn(sv, "", 0);
 
-               do {
+               for (;;) {
                    if (*s == '0' && isDIGIT(s[1]))
                        yyerror("Octal number in vector unsupported");
                    rev = atoi(s);
-                   s = ++pos;
-                   while (isDIGIT(*pos))
-                       pos++;
-
-                   if (rev > 127) {
-                       tmpend = uv_to_utf8(tmpbuf, rev);
-                       utf8 = TRUE;
-                   }
+                   tmpend = uv_to_utf8(tmpbuf, rev);
+                   utf8 = utf8 || rev > 127;
+                   sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
+                   if (*pos == '.' && isDIGIT(pos[1]))
+                       s = ++pos;
                    else {
-                       tmpbuf[0] = (U8)rev;
-                       tmpend = &tmpbuf[1];
+                       s = pos;
+                       break;
                    }
-                   sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
-               } while (*pos == '.' && isDIGIT(pos[1]));
-
-               if (*s == '0' && isDIGIT(s[1]))
-                   yyerror("Octal number in vector unsupported");
-               rev = atoi(s);
-               s = pos;
-               tmpend = uv_to_utf8(tmpbuf, rev);
-               utf8 = utf8 || rev > 127;
-               sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
+                   while (isDIGIT(*pos))
+                       pos++;
+               }
 
                SvPOK_on(sv);
                SvREADONLY_on(sv);