Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Perl Hashes

by johngg (Canon)
on Apr 24, 2007 at 10:29 UTC ( [id://611687]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://611687]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found