Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Dynamically Building Variable Names

by jhourcle (Prior)
on Apr 22, 2005 at 17:37 UTC ( [id://450510]=note: print w/replies, xml ) Need Help??


in reply to Re: Dynamically Building Variable Names
in thread Dynamically Building Variable Names

Or, just to keep it simple, and more like what was requested originally (as there may be something else that we don't know about, that would have problems if it were a deep structure), you can use a flat hash:

my %data; $data{'exampleother1'} = 'something'; $data{'exampleother2'} = 'something else'; $data{$var1.$var2.$number} = $value; # or using a hashref my $data; $data->{'exampleother1'} = 'something'; $data->{'exampleother2'} = 'something else'; $data->{$var1.$var2.$number} = $value;

The deeper structure has advantages if you might have values for ($var1.$var2) that collide. (if those should be two discrete values, then use a hash of hashes or some other complex structure. If they should be the same value, then just use a single dimensional hash).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found