(Note: I gave monarch a chance to fix his own article in /msg, but he blew me off in /msg and is now ignoring me, so I have to make this a public comment instead. I think that qualifies as "trying to do the right thing first".)my $stringnum = "\$string" . $num; my $result = eval $stringnum;
Please don't use eval for this without adding a big "don't do this, though". It invokes the compiler needlessly, and it also encourages variable variables, which is a broken form of programming.
I'd elaborate, but other answers in this thread already have better solutions. I just needed to flag monarch's solution as bad since he was unwilling to do that himself.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
In reply to Re^2: Printing Variable Variables
by merlyn
in thread Printing Variable Variables
by awohld
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |