RosettaCodeData/Task/Dynamic-variable-names/Perl/dynamic-variable-names-1.pl

8 lines
327 B
Perl
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
print "Enter a variable name: ";
$varname = <STDIN>; # type in "foo" on standard input
chomp($varname);
$$varname = 42; # when you try to dereference a string, it will be
# treated as a "symbolic reference", where they
# take the string as the name of the variable
print "$foo\n"; # prints "42"