M.J.T. Guy [Sun, 15 Jun 1997 07:27:52 +0000 (19:27 +1200)]
jmm@elegant.com (John Macdonald) wrote
> The other issue is an annoyance rather than a stopper. As cited
> in perl425traps, "stuff${'var}more stuff" is no longer
> supported, only $::var and ${::var} are recognized with a
> string. Changing the ' to :: means that the code is no longer
> perl4 compatible. I don't want to have ongoing work on two
> versions (perl4 and perl5), so the only good workaround, for
> now, is to break the string into:
>
> "stuff" . $'var . "more stuff"
>
> As I said, it's an annoyance - there's lots of them in the code
> and a significant proportion of the conversions to . would cause
> lines that ought to be wrapped for readability purposes.
>
> Is there any hope of getting the $' syntax recognized within
> strings? (Sigh, I'm sure it's too late for it to go into
> 5.004_01, though.)
I think it would be a very bad idea to retrofit this. Having single
quotes which don't start quoted strings is a syntactic ambiguity
nightmare. Consider soft references such as "stuff${'var'}more stuff".
(I presume that's why it had to be removed.)
You can avoid this problem, and not extend the lines quite as much, by
explicitly including the package name:
"stuff${main'var}more stuff"
which works compatibly in perl4 and perl5.
Attached is a suggested patch for perltrap.
p5p-msgid: E0wdKJY-00010w-00@taurus.cus.cam.ac.uk
# perl4 prints: x=10
# perl5 prints: Can't find string terminator "'" anywhere before EOF
+You can avoid this problem, and remain compatible with perl4, if you
+always explicitly include the package name:
+
+ $x = 10 ;
+ print "x=${main'x}\n" ;
+
Also see precedence traps, for parsing C<$:>.
=item * BugFix