Scalar to command, arrays in hashes?

I want to store a bunch of arrays, and then store a single array list with all of the other arrays inside.  So:

@arrayLists = ("dog","cat","rat");
@dog = ("fido", "rex", "king");
@cat = ("tabby", "Kitty", "Morris");
@rat = ("Ratbert", "Sam", "Rudy");

Is there a way to retrieve the values from dog, cat, and rat, by using the values in arraylists?

Also, could I store this all in a single hash?

%masterList = (dog => @dog, cat => ("tabby","rex","king") ...etc for rat)

How would I retrieve these values?

There's gotta be a way...

Who is Participating?
RobWMartinConnect With a Mentor Commented:
I said use array references, but actually I used anonymous arrays.  Ultimately the same thing as far as the hash value is concerned.  This would be more of an example of an array reference:


   dog => \@dogs,

Otherwise, everything is the same.

You need to use array references in the case of the hash (which, by the way, seems like the best structure to use):

  dog => ["fido","rex","king"],
  cat => ["tabby","fluffy","princess"],

print "My third dog is $masterList{'dog'}[2]\n";

would print

My third dog is king

try this. with this you dont even need the masterlist hash!!


@arrayLists = ("dog","cat","rat");
@dog = ("fido", "rex", "king");
@cat = ("tabby", "Kitty", "Morris");
@rat = ("Ratbert", "Sam", "Rudy");

#%masterList = (dog => @dog, cat => @cat rat => @rat)

foreach $arr (@arrayLists){
    print $_,"\t";
  print "\n";
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

%masterList = map{$_,\@{$_}} @arrayLists;
were you able to check the comments that were offered?

let us know :)
RaydotAuthor Commented:
You guys are brilliant.  While ozo and man went above and beyond, RobW did answer first.  Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.