develooper Front page | perl.perl5.porters | Postings from June 2016

[perl #128478] Change in behaviour of "$foo::$bar" in 5.18

Thread Previous
Father Chrysostomos
June 25, 2016 04:51
[perl #128478] Change in behaviour of "$foo::$bar" in 5.18
Message ID:
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #128478]
# in the subject line of all future correspondence about this issue. 
# <URL: >

In perl 5.16 and earlier, "$foo::$bar" parsed as:

    $foo:: . $bar

In perl 5.18, it accidentally started being parsed as:

    $foo . "::" . $bar

(I say accidentally, because commit 07f7264624e0, which made the change, does not appear to have been made for this purpose, and its commit message does not even hint at this particular change in parsing.)

Now one module, Sub::Attribute (admittedly brand new and still at 0.01), has inadvertently started relying on the new behaviour.  (See <>.)

The *real* problem is that we now have a discrepancy between "$foo::$bar" and "$foo::@bar":

$ ./perl -Ilib -MO=Deparse,-q -e '"$foo::$bar"'
$foo . '::' . $bar;
-e syntax OK
$ ./perl -Ilib -MO=Deparse,-q -e '"$foo::@bar"'
$foo:: . join($", @bar);
-e syntax OK

So, what should we do about this?  Should we (a) revert to the old behaviour?  (Fixing that one module is easy enough.)  Or should we (b) make "$foo::@bar" consistent with "$foo::$bar".

I prefer option a.  Option b is harder, in that we have to decide where exactly to draw the line.  Do we stop $foo:: from being interpolated at all?  Do we only cut it off at $foo before $ and @?  Etc.

The change, BTW, did not only affect double-quoted strings, but also print $foo::$bar:

$ perl5.14.4 -e 'print $foo::$bar'
Scalar found where operator expected at -e line 1, near "$foo::$bar"
	(Missing operator before $bar?)
Can't use an undefined value as a symbol reference at -e line 1.

(The ‘Scalar found where operator expected’ is bogus.  [I reported that in another ticket some years ago.] The fact that it does with ‘Can't use an undefined value’ shows that the program compiles and runs.)

$ perl5.18.1 -e 'print $foo::$bar'
Bad name after :: at -e line 1.

Now we have a very unhelpful error message.  (The same unhelpful message you get for ‘foo::bar::$baz’, at least as far back as 5.8.7.)

Also, B::Deparse is wrong now:

$ ./perl -Ilib -MO=Deparse -e '"${foo::}$a"'
-e syntax OK


Father Chrysostomos

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About