[comp.lang.perl] Nested quoting.

flee@cs.psu.edu (Felix Lee) (02/01/91)

Larry Wall wrote:
>Perl doesn't allow nested quote interpretation either, which also forces
>you to make temporaries at times.  I consider this to be an anti-obfuscatory
>feature.

Urm, how about this?
	$x{'hello'} = 'world';
	print "$x{\"hello\"}";

Various strange constructs give various strange non-results.  None of
the following work:
	print "${x = \"${y = \\\"$z\\\"}\"}";
	print "${x = \"${y = qq\\$z\\}\"}";
	print "${x = \"${y = qq\$z\}\"}";

But this weird thing does:
	$x = 'world'; $y = 'hello';
	print "${x=\"${y=${z=qq/$y/,$y=qq/$x/},$x=qq/$z/} ${z=${x=qq/$y/,$y=qq/$z/},$z=qq/$x/}\"}\n";

I'm a little dazed at how this works.  I can barely reason through the
sequence of execution.

Marginal behavior is a wonderful thing.

An almost-Perl parser that I've been sporadically working on won't
accept any of the above, but it will accept
	print "$x{"hello"}";
which is perhaps mildly strange, but pretty natural.  I'm not sure yet
whether this is a feature or a bug.  (It's a side-effect of having a
scanner that will tokenize double-quoted strings for the parser.)
--
Felix Lee	flee@cs.psu.edu