http://qs321.pair.com?node_id=611687


in reply to Perl Hashes

You can but there are two problems with your code. First, variables are not interpolated inside qw{ ... } so you are just getting the literal variable name so you need to set up the hash using key/value pairs in a list. Second, you need to disambiguate the $dw from the '_VAR' because $dw_VAR is also a valid variable name; you can do this by saying ${dw}_ARG. You are setting up a hash reference and it is probably less confusing if you use the { key => value, ... } anonymous hash constructor.

It is a good idea to always do use strict; and use warnings at the top of your code. That would help you catch things like undeclared variables.

use strict; use warnings; my $dw = q{dw_urg}; my $dw_TG = { var => qq{${dw}_VAR}, str => qq{${dw}_STR}, mkt => qq{${dw}_MKT}, };

I hope this is useful.

Cheers,

JohnGG