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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.