Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Using Variable Value as Variable Name

by sundialsvc4 (Abbot)
on Jun 28, 2012 at 14:02 UTC ( #978940=note: print w/replies, xml ) Need Help??

in reply to Using Variable Value as Variable Name

Let me strongly echo what I am sure is a pretty-universal sentiment here:   don’t expose the variable-name space, even if you find that you can.   This creates a program that is not only un-debuggable, but also wantonly open to sabotage.   (And, yeah, you have to think about things like “sabotage.”)

If you want to open access to specific variables’ values by name, here is one safe way to do so:   create a hash, whose keys are the variable-names, and whose contents for each key is a reference to that variable.   This is a controllable and debuggable situation, because “not just any ol’ name you might come up with” can be used; only what exists().   Now, presto!, comes the first obvious simplification:   why use a variable-name when you can simply refer to the hash?

Even though we like to say “TMTOWTDI™ == There’s More Than One Way To Do It,” there are definitely ways that are recommend vs. others that are not...

  • Comment on Re: Using Variable Value as Variable Name

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978940]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2018-04-21 03:09 GMT
Find Nodes?
    Voting Booth?