Home: Fun With Perl: Perl Quizzes - Learn Perl the Fun Way:
perl dyname variable name help

New User

Aug 8, 2011, 11:30 PM

Views: 38555
perl dyname variable name help

Hi every one:

I been looking for solution dynamically create a variable name.
something like this:

my new21MO = "testing";
my $number = 21;
my $exName = "MO";

my $string = "new" . $number . $MO;
print $$string; <------------- I tested this aren't working.

is there a way to declare this string to a variable?
please help me out.

Veteran / Moderator

Aug 10, 2011, 9:39 AM

Views: 38519
Re: [chefchanyu] perl dyname variable name help

What you're asking about is called symbolic references and using them is a very bad idea.

Use a hash instead of symbolic references.