in reply to Dynamically name the variable and get it's value from Module
And, once corrected by adding quote marks, you would get a second error at runtime:Bareword "Chennai" not allowed while "strict subs" in use at ...
Symbolic references were once (before Perl 5, i.e. more than 20 years ago) the only way to do certain types of things similar to what is sometimes done in shell scripting, but they are really frown upon in today's Perl programming. They are really a source of errors often difficult to track. To the point that they are forbidden with strictures (there are still there with no strictures only to preserve compatibility of very old programs). Use a hash instead.$ perl -e ' > use strict; > use warnings; > > our $TO_Chennai = "foobar"; > > my $circle = "Chennai"; > my $file = "TO_" . "$circle"; > print $$file;' Can't use string ("TO_Chennai") as a SCALAR ref while "strict refs" in + use at -e line 9.
Do yourself a favor: use strict; and use warnings;, and the compiler will tell you immediately about many of your mistakes, typos, etc., and you'll gain a lot of time.
|
|---|