Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array naming conventions

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
0
0
US
Hello, I was wondering if it was possible to have an array named as a variable similar to this @$var and this @$var$vartoo ?

The reason I was asking is that I got 1 array that I would like to have an array pull the names of the previous array elements.


@colors = bright dull dark

@$colors$dark = blue black

@$colors$dark$blue = navy


I'm not sure about the best method to use in going about this, or even if it's feasible or not.

Thanks In advance :)
 
have a look at perldoc perlreftut Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
That's easier to do a hash of hashes better than arrays:
Code:
# The outside set of brackets are parens
# All others are curly brackets
%colors = (
   'bright' => {
      'red' => 'tomato',
      'yellow' => 'golden',
   },
   'dull' => {
      'gray' => 'darkgray',
      'green' => 'olive',
   },
   'dark' => {
      'blue' => 'navy',
      'black' => 'black',
   },
);

print $colors{'dark'}{'blue'}; # prints navy
print $colors{'bright'}{'red'}; # prints tomato
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top