Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Perl Hashes

by johngg (Canon)
on Apr 24, 2007 at 10:29 UTC ( #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.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2023-01-30 05:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found