in reply to RE: How Does Interpolation Work?
in thread How Does Interpolation Work?
Looking for ${R}[0], however, perl -w says this:
Name "main::R" used only once: possible typo at - line 2.
So, when you add characters that look like a variable specification Perl is only looking in the symbol table.
If you don't make $R lexical, it will work like you originally expected:
prints "foo[0]"$R="foo"; print "${R}[0]\n";
To get perl to keep interpolating, just keep adding {}'s:
prints 42use vars qw/$R @foo/; $R="foo"; @foo = (42); print "${${R}}[0]\n";
:-)
BTW, I seem remember some code posted some time ago which
did this kind of "multiple interpolation." I can't find it.
Anyone know what node that is (or am I just hallucinating
again?
("Too much LDS" -- Kirk about Spock in ST:IV))
Update: Here it is: Double Interpolation of a String
Russ
Brainbench 'Most Valuable Professional' for Perl
|
|---|