Okay, you made $R lexical with my. ${R} is a
symbolic reference to the scalar variable named 'R'. Just
left alone, Perl will figure out you want the lexical
variable and not a variable in the symbol table.
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:
$R="foo";
print "${R}[0]\n";
prints "foo[0]"
To get perl to keep interpolating, just keep adding {}'s:
use vars qw/$R @foo/;
$R="foo";
@foo = (42);
print "${${R}}[0]\n";
prints 42
:-)
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 |